Development/MySql

[MySQL] 데이터 치환하기

곽진돔 2023. 3. 29. 14:47

replace()함수를 사용하여 데이터를 치환할 수 있다.

# 테이블 데이터 조회
select * from table_name 
where idx = 1 and status_code!= 3

# 변경할 값 확인
SELECT REPLACE(name, 'ABC0', 'ABC00') AS 'replaced_data' FROM table_name 
where idx = 1 and status_code!= 3 and name like "%ABC0%" 

# update로 값 변경
UPDATE table_name  SET name = REPLACE(name, 'ABC0', 'ABC00')
where idx = 1 and status_code!= 3 and name like "%ABC0%"

검색결과에서 abc0과 abc00의 결과가 달라서 데이터를 수정했다. (검색엔진 문제 같은데 정확한 원인은 아직 모름)

REPLACE()를 이용하면 된다.