WITH T AS (SELECT 'M1' ID, '130000' A, 3 B FROM DUAL UNION ALL SELECT 'M2', 'E090000', 3 FROM DUAL UNION ALL SELECT 'M3', 'QWEWU270000', 3 FROM DUAL UNION ALL SELECT 'M4', '234567', 3 FROM DUAL UNION ALL SELECT 'M5', 'W123456', 3 FROM DUAL UNION ALL SELECT 'M6', 'E000000', 3 FROM DUAL UNION ALL SELECT 'M7', '000000', 4 FROM DUAL) SELECT ID,CASE WHEN B=3 THEN substr(a, 1, regexp_instr(a,'[[:digit:]]')-1)|| to_char(substr(a, nvl(LENGTH(REGEXP_REPLACE(A,'[[:digit:]]')), 0)+1) + 10000,'fm000000') ELSE A END A, B FROM T;
이런 식이면 되지 않을까요?? 막 짜서 지저분하긴 하네요;;
WITH t AS ( SELECT 'M1' id, '130000' a, 3 b FROM dual UNION ALL SELECT 'M2', 'E090000' , 3 FROM dual UNION ALL SELECT 'M3', 'WU270000' , 3 FROM dual UNION ALL SELECT 'M4', '234567' , 3 FROM dual UNION ALL SELECT 'M5', 'W123456' , 3 FROM dual UNION ALL SELECT 'M6', 'ERTY000000', 3 FROM dual UNION ALL SELECT 'M7', '000000' , 4 FROM dual ) SELECT id, a, b , DECODE(b, 3 , SUBSTR(a, 1, LENGTH(a) - 6) || LPAD(SUBSTR(a, -6) + 10000, 6, '0') , a) AS a_new FROM t ;