1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 퀴즈겸.. 질문입니다. WITH C_T AS ( SELECT '00001' AS ID, '[뭐뭐뭐] @ 님은 대출금 @ 이 @ 가능하십니다.' AS CTNT FROM DUAL UNION ALL SELECT '00002' AS ID, '[뭐뭐뭐] @ 님의 결제예정일은 @일 입니다.' AS CTNT FROM DUAL ), P_T AS ( SELECT 'A000000001' AS CUST_NO, '홍길동' AS ADD_INF_CTNT, 1 AS LOC_INF FROM DUAL UNION ALL SELECT 'A000000001' AS CUST_NO, '150,000,000' AS ADD_INF_CTNT, 2 AS LOC_INF FROM DUAL UNION ALL SELECT 'A000000001' AS CUST_NO, '2.6%' AS ADD_INF_CTNT, 3 AS LOC_INF FROM DUAL UNION ALL SELECT 'A000000002' AS CUST_NO, '이순신' AS ADD_INF_CTNT, 1 AS LOC_INF FROM DUAL UNION ALL SELECT 'A000000002' AS CUST_NO, '200,000,000' AS ADD_INF_CTNT, 2 AS LOC_INF FROM DUAL UNION ALL SELECT 'A000000002' AS CUST_NO, '3.0%' AS ADD_INF_CTNT, 3 AS LOC_INF FROM DUAL UNION ALL SELECT 'A000000003' AS CUST_NO, '김개똥' AS ADD_INF_CTNT, 1 AS LOC_INF FROM DUAL UNION ALL SELECT 'A000000003' AS CUST_NO, '210,000,000' AS ADD_INF_CTNT, 2 AS LOC_INF FROM DUAL UNION ALL SELECT 'A000000003' AS CUST_NO, '3.0%' AS ADD_INF_CTNT, 3 AS LOC_INF FROM DUAL ) SELECT A.CTNT , B.ADD_INF_CTNT , B.LOC_INF , REGEXP_REPLACE(CTNT, '@' , ADD_INF_CTNT, 1, LOC_INF) FROM C_T A , P_T B WHERE A.ID = '00001' /* 원하는결과 : [뭐뭐뭐] 홍길동 님은 대출금 150,000,000 이 2.6% 가능하십니다. [뭐뭐뭐] 이순신 님은 대출금 200,000,000 이 3.0% 가능하십니다. [뭐뭐뭐] 김개똥 님은 대출금 210,000,000 이 3.0% 가능하십니다. ※LOC_INF은 @의 순서입니다. */ 쉽게생각했는데 어렵네요 ㅠㅠ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | --말씀 하신 결과와 동일하게 나오나 결제 예정일 내용까지 취하려면 많은 수정이 필요합니당 ~ SELECT CUST_NO, REGEXP_REPLACE(CTNT, '@( 님.*)@( 이.*)@' , NM|| '\1' ||PRICE|| '\2' ||RATE) FROM ( SELECT CUST_NO, MAX (CTNT) AS CTNT, MAX (DECODE(LOC_INF, 1, ADD_INF_CTNT, '' )) AS NM, MAX (DECODE(LOC_INF, 2, ADD_INF_CTNT, '' )) AS PRICE, MAX (DECODE(LOC_INF, 3, ADD_INF_CTNT, '' )) AS RATE FROM C_T A, P_T B WHERE A.ID = '00001' GROUP BY CUST_NO ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | WITH c_t AS ( SELECT '00001' id, '[뭐뭐뭐] @ 님은 대출금 @ 이 @ 가능하십니다.' ctnt FROM dual UNION ALL SELECT '00002' , '[뭐뭐뭐] @ 님의 결제예정일은 @일 입니다.' FROM dual ) , p_t AS ( SELECT 'A000000001' cust_no, '00001' id, 1 loc_inf, '홍길동' add_inf_ctnt FROM dual UNION ALL SELECT 'A000000001' , '00001' , 2, '150,000,000' FROM dual UNION ALL SELECT 'A000000001' , '00001' , 3, '2.6%' FROM dual UNION ALL SELECT 'A000000002' , '00001' , 1, '이순신' FROM dual UNION ALL SELECT 'A000000002' , '00001' , 2, '200,000,000' FROM dual UNION ALL SELECT 'A000000002' , '00001' , 3, '3.0%' FROM dual UNION ALL SELECT 'A000000003' , '00001' , 1, '김개똥' FROM dual UNION ALL SELECT 'A000000003' , '00001' , 2, '210,000,000' FROM dual UNION ALL SELECT 'A000000003' , '00001' , 3, '3.0%' FROM dual UNION ALL SELECT 'A000000001' , '00002' , 1, '홍길동' FROM dual UNION ALL SELECT 'A000000001' , '00002' , 2, '2013.08.25' FROM dual UNION ALL SELECT 'A000000002' , '00002' , 1, '이순신' FROM dual UNION ALL SELECT 'A000000002' , '00002' , 2, '2013.09.01' FROM dual UNION ALL SELECT 'A000000003' , '00002' , 1, '김개똥' FROM dual UNION ALL SELECT 'A000000003' , '00002' , 2, '2013.08.31' FROM dual ) SELECT a.id , b.cust_no , REGEXP_SUBSTR(a.ctnt, '[^@]+' ) || LISTAGG( b.add_inf_ctnt || REGEXP_SUBSTR(a.ctnt, '[^@]+' , 1, b.loc_inf + 1) , '' ) WITHIN GROUP ( ORDER BY b.loc_inf) AS ctnt FROM c_t a , p_t b WHERE a.id = b.id AND a.id = '00001' GROUP BY a.id, b.cust_no, REGEXP_SUBSTR(a.ctnt, '[^@]+' ) ORDER BY a.id, b.cust_no ; |
1 2 3 4 5 6 7 8 9 10 11 12 13 | -- SUBSTRB('오_라_클_클_럽', 1, 5) -- 원하는 결과는 '오_라' 이자만 UTF8에서는 '오_ '이 나오게 된다. SELECT v v0 , SUBSTRB(v, 1, 5) v1 , SUBSTRB(v, 1, 5 + LENGTHB(x) - LENGTH(x)) v2 FROM ( SELECT v , SUBSTRB( CONVERT (v, 'KO16MSWIN949' ), 1, 5) x FROM ( SELECT '오_라_클_클_럽' v FROM dual) ) ; -- v0 : '오_라_클_클_럽' -- v1 : '오_ ' -- v2 : '오_라' |