안녕하세요.
오라클에서 '한국' 을 'gksrnr' 이렇게 변환하거나 'gksrnr' 을 '한국' 이렇게 변환 할 수 있는 방법이 있는지 알고 싶습니다.
조합형 한글 대상으로 만들어 봤습니다. 완성되지 않은 글자는 안됩니다.(자음만 또는 모음만 있는글자)
WITH t1 AS ( -- 초성(588) -- SELECT 'ㄱ' k1, 'r' e1, 0 n1 FROM dual UNION ALL SELECT 'ㄲ', 'R', 1 FROM dual UNION ALL SELECT 'ㄴ', 's', 2 FROM dual UNION ALL SELECT 'ㄷ', 'e', 3 FROM dual UNION ALL SELECT 'ㄸ', 'E', 4 FROM dual UNION ALL SELECT 'ㄹ', 'f', 5 FROM dual UNION ALL SELECT 'ㅁ', 'a', 6 FROM dual UNION ALL SELECT 'ㅂ', 'q', 7 FROM dual UNION ALL SELECT 'ㅃ', 'Q', 8 FROM dual UNION ALL SELECT 'ㅅ', 't', 9 FROM dual UNION ALL SELECT 'ㅆ', 'T', 10 FROM dual UNION ALL SELECT 'ㅇ', 'd', 11 FROM dual UNION ALL SELECT 'ㅈ', 'w', 12 FROM dual UNION ALL SELECT 'ㅉ', 'W', 13 FROM dual UNION ALL SELECT 'ㅊ', 'c', 14 FROM dual UNION ALL SELECT 'ㅋ', 'z', 15 FROM dual UNION ALL SELECT 'ㅌ', 'x', 16 FROM dual UNION ALL SELECT 'ㅍ', 'v', 17 FROM dual UNION ALL SELECT 'ㅎ', 'g', 18 FROM dual ) , t2 AS ( -- 중성(모음,28) -- SELECT 'ㅏ' k2, 'k' e2, 0 n2 FROM dual UNION ALL SELECT 'ㅐ', 'o' , 1 FROM dual UNION ALL SELECT 'ㅑ', 'i' , 2 FROM dual UNION ALL SELECT 'ㅒ', 'O' , 3 FROM dual UNION ALL SELECT 'ㅓ', 'j' , 4 FROM dual UNION ALL SELECT 'ㅔ', 'p' , 5 FROM dual UNION ALL SELECT 'ㅕ', 'u' , 6 FROM dual UNION ALL SELECT 'ㅖ', 'P' , 7 FROM dual UNION ALL SELECT 'ㅗ', 'h' , 8 FROM dual UNION ALL SELECT 'ㅘ', 'hk', 9 FROM dual UNION ALL SELECT 'ㅙ', 'ho', 10 FROM dual UNION ALL SELECT 'ㅚ', 'hl', 11 FROM dual UNION ALL SELECT 'ㅛ', 'y' , 12 FROM dual UNION ALL SELECT 'ㅜ', 'n' , 13 FROM dual UNION ALL SELECT 'ㅝ', 'nj', 14 FROM dual UNION ALL SELECT 'ㅞ', 'np', 15 FROM dual UNION ALL SELECT 'ㅟ', 'nl', 16 FROM dual UNION ALL SELECT 'ㅠ', 'b' , 17 FROM dual UNION ALL SELECT 'ㅡ', 'm' , 18 FROM dual UNION ALL SELECT 'ㅢ', 'ml', 19 FROM dual UNION ALL SELECT 'ㅣ', 'l' , 20 FROM dual ) , t3 AS ( -- 종성(1) -- SELECT '' k3, '' e3, 0 n3 FROM dual UNION ALL SELECT 'ㄱ', 'r' , 1 FROM dual UNION ALL SELECT 'ㄲ', 'R' , 2 FROM dual UNION ALL SELECT 'ㄳ', 'rt', 3 FROM dual UNION ALL SELECT 'ㄴ', 's' , 4 FROM dual UNION ALL SELECT 'ㄵ', 'sw', 5 FROM dual UNION ALL SELECT 'ㄶ', 'sg', 6 FROM dual UNION ALL SELECT 'ㄷ', 'e' , 7 FROM dual UNION ALL SELECT 'ㄹ', 'f' , 8 FROM dual UNION ALL SELECT 'ㄺ', 'fr', 9 FROM dual UNION ALL SELECT 'ㄻ', 'fa', 10 FROM dual UNION ALL SELECT 'ㄽ', 'ft', 11 FROM dual UNION ALL SELECT 'ㄼ', 'fq', 12 FROM dual UNION ALL SELECT 'ㄾ', 'fx', 13 FROM dual UNION ALL SELECT 'ㄿ', 'fv', 14 FROM dual UNION ALL SELECT 'ㅀ', 'fg', 15 FROM dual UNION ALL SELECT 'ㅁ', 'a' , 16 FROM dual UNION ALL SELECT 'ㅂ', 'q' , 17 FROM dual UNION ALL SELECT 'ㅄ', 'qt', 18 FROM dual UNION ALL SELECT 'ㅅ', 't' , 19 FROM dual UNION ALL SELECT 'ㅆ', 'T' , 20 FROM dual UNION ALL SELECT 'ㅇ', 'd' , 21 FROM dual UNION ALL SELECT 'ㅈ', 'w' , 22 FROM dual UNION ALL SELECT 'ㅊ', 'c' , 23 FROM dual UNION ALL SELECT 'ㅋ', 'z' , 24 FROM dual UNION ALL SELECT 'ㅌ', 'x' , 25 FROM dual UNION ALL SELECT 'ㅍ', 'v' , 26 FROM dual UNION ALL SELECT 'ㅎ', 'g' , 27 FROM dual ) -- 1. 'gksrnr' --> '한국' SELECT LISTAGG(TO_CHAR(v)) WITHIN GROUP(ORDER BY gb) FROM ( SELECT gb , NCHR(SUM(n)) v FROM (SELECT lv , x , SUM(DECODE(x, 1, 1)) OVER(ORDER BY lv) gb , DECODE(x, 1, 44032 + n1 * 588 , 2, n2 * 28 , 3, n3 ) n FROM (SELECT lv , CASE WHEN n2 IS NOT NULL AND LAG(n2) OVER(ORDER BY lv) IS NULL THEN 2 WHEN n2 IS NOT NULL AND LAG(n2) OVER(ORDER BY lv) IS NOT NULL THEN 0 WHEN n2 IS NULL AND LEAD(n2) OVER(ORDER BY lv) IS NOT NULL THEN 1 WHEN n2 IS NULL AND LAG(n2) OVER(ORDER BY lv) IS NULL AND LEAD(n2) OVER(ORDER BY lv) IS NULL THEN 0 ELSE 3 END x , CASE WHEN n2 IS NOT NULL AND LEAD(n2) OVER(ORDER BY lv) IS NOT NULL THEN v2 WHEN n2 IS NULL AND LEAD(n2, 1) OVER(ORDER BY lv) IS NULL AND LEAD(n2, 2) OVER(ORDER BY lv) IS NULL THEN v2 ELSE v1 END v FROM (SELECT LEVEL lv , SUBSTR(v, LEVEL, 1) v1 , SUBSTR(v, LEVEL, 2) v2 FROM (SELECT 'gksrnr' v FROM dual) CONNECT BY LEVEL <= LENGTH(v) ) a , t2 b WHERE a.v1 = b.e2(+) ) a , t1 , t2 , t3 WHERE DECODE(x, 1, a.v) = t1.e1(+) AND DECODE(x, 2, a.v) = t2.e2(+) AND DECODE(x, 3, a.v) = t3.e3(+) ) GROUP BY gb ) ; 2. '똠방각하' --> 'Ehaqkdrkrgk' SELECT LISTAGG(e1 || e2 || e3) WITHIN GROUP(ORDER BY lv) v FROM (SELECT LEVEL lv , SUBSTR(v, LEVEL, 1) v , ASCII(UNISTR(SUBSTR(v, LEVEL, 1))) - 44032 n FROM (SELECT '똠방각하' v FROM dual) x CONNECT BY LEVEL <= LENGTH(v) ) a , t1 , t2 , t3 WHERE t1.n1(+) = FLOOR(n / 588) AND t2.n2(+) = FLOOR(MOD(n, 588) / 28) AND t3.n3(+) = MOD(MOD(n, 588) , 28) ;