programing

SQL UPDATE에서 str_replace?

iphone6s 2023. 7. 26. 21:40
반응형

SQL UPDATE에서 str_replace?

다음은 샘플 표입니다.

name       |   picture

John S.    |   http://servera.host.com/johns.png
Linda B.   |   http://servera.host.com/lindab.png
...

수백 개의 기록이 더 있다고 치자.

또한 서버를 "servera"에서 "serverb"로 이동했다고 가정해 보겠습니다.

모든 레코드가 올바른 서버 이름을 읽을 수 있도록 "그림" 열에 있는 내용의 이름을 바꾸기 위해 쿼리 하나로 이 테이블에 들어갈 수 있습니까?

T-SQL:

update TBL 
   set picture = Replace(picture, 'servera', 'serverb') 
 where picture like '%servera%'

오라클:

update TBL 
   set picture = replace(picture, 'servera', 'serverb') 
 where picture like '%servera%'

MySQL:

update TBL 
   set picture = REPLACE(picture, 'servera', 'serverb') 
 where picture like '%servera%'
UPDATE users
SET picture = REPLACE(picture, 'http://servera.host.com/', 'http://serverb.host.com/')
WHERE picture LIKE 'http://servera.host.com/%';

something server asomething.jpg'이라는 이름의 이미지를 '수정'하는 것을 걱정하기 때문에 더 많은 문자열을 포함합니다.저도 base_url 테이블을 가지고 이미지 파일 이름을 사용자에게 저장하는 것에 대해 생각할 수도 있지만, 그건 당신이 물어본 질문이 아닙니다;-);-)

언급URL : https://stackoverflow.com/questions/3944000/str-replace-in-sql-update

반응형