저희가 우선 기본적으로 한개의 컬럼에 들어가 있는 값을 나누는걸 함수로 만들어서 사용하는데 가끔식 나눠지지 않는 주소들이 있더라고요
기본적으로 다 잘되는데 이런케이스는 잘안되서 혹시 사용하시는 sql이 있ㅇ실까요?
WITH m_data
AS
(
SELECT '전라북도 전주시 완산구 홍산북로 21-7(효자2가 1230-8) 스타빌딩 4층 ㈜팜한농' AS addr FROM dual
UNION ALL
SELECT '광주광역시 광산구 임방울대로 826번길 20 수연빌딩 3층 ㈜팜한농' AS addr FROM dual
UNION ALL
SELECT '전남 무안군 삼향면 대죽동로 46 대호빌딩 4층 ㈜팜한농' AS addr FROM dual
UNION ALL
SELECT '전북 전주시 완산구 효자동3가 1613-1 로뎀하우스 401호' AS addr FROM dual
)
SELECT
substr(
addr,1,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+instr(
substr(addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')
+1),' ')) ||
decode(
substr(addr,
length(substr(
addr,1,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+instr(
substr(addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')
+1),' ')))-1,1
), '구',
substr(
substr(
addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+instr(
substr(addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+1),' ')
+1)
,1,instr(substr(
addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+instr(
substr(addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+1),' ')
+1)
,' '))
) as ADDRESS1,
substr(
substr(
addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+instr(
substr(addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+1),' ')
+1)
,
nvl(
length(decode(
substr(addr,
length(substr(
addr,1,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+instr(
substr(addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')
+1),' ')))-1,1
), '구',
substr(
substr(
addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+instr(
substr(addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+1),' ')
+1)
,1,instr(substr(
addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+instr(
substr(addr,instr(addr,' ')+instr(substr(addr,instr(addr,' ')+1),' ')+1),' ')
+1)
,' '))
)
),0)+1
) as ADDRESS2
FROM m_data
WITH m_data AS ( SELECT '전라북도 전주시 완산구 홍산북로 21-7(효자2가 1230-8) 스타빌딩 4층 ㈜팜한농' AS addr FROM dual UNION ALL SELECT '광주광역시 광산구 임방울대로 826번길 20 수연빌딩 3층 ㈜팜한농' AS addr FROM dual UNION ALL SELECT '전남 무안군 삼향면 대죽동로 46 대호빌딩 4층 ㈜팜한농' AS addr FROM dual UNION ALL SELECT '전북 전주시 완산구 효자동3가 1613-1 로뎀하우스 401호' AS addr FROM dual UNION ALL SELECT '전북 전주시 완산구 효자동3가 1613-1 로뎀하우스 401호' AS addr FROM dual ) SELECT ADDR , TRIM(SUBSTR(ADDR, 1, REGEXP_INSTR(ADDR, '[^ ]+', 1, REGEXP_COUNT(ADDR,' ')+2-4) -1)) ADDR1 , (REGEXP_SUBSTR(ADDR, '[^ ]+', 1, REGEXP_COUNT(ADDR,' ')+2-4) || ' ' || REGEXP_SUBSTR(ADDR, '[^ ]+', 1, REGEXP_COUNT(ADDR,' ')+2-3) || ' ' || REGEXP_SUBSTR(ADDR, '[^ ]+', 1, REGEXP_COUNT(ADDR,' ')+2-2) || ' ' || REGEXP_SUBSTR(ADDR, '[^ ]+', 1, REGEXP_COUNT(ADDR,' ')+2-1)) ADDR2 FROM M_DATA A; 공백이 기준이라면 데이터도 명확하게 공백이 있어야 겠네요..