[퀴즈] 숫자를 한글로 표기
문제. 숫자를 한글로 표기하는 쿼리문을 작성하세요.
WITH t AS
(
SELECT 123456789012345 amt FROM dual
UNION ALL SELECT 29000 FROM dual
UNION ALL SELECT 39840 FROM dual
)
SELECT * FROM t
;
[결과]
AMT | V |
123456789012345 | 일백이십삼조사천오백육십칠억팔천구백일만이천삼백사십오 |
29000 | 이만구천 |
39840 | 삼만구천팔백사십 |
[정답보기] <=== 트리플클릭
SELECT amt
, TRANSLATE
( SUBSTR(v, 1,1)||DECODE(SUBSTR(v, 1,1),0,'','천')
|| SUBSTR(v, 2,1)||DECODE(SUBSTR(v, 2,1),0,'','백')
|| SUBSTR(v, 3,1)||DECODE(SUBSTR(v, 3,1),0,'','십')
|| SUBSTR(v, 4,1)||DECODE(SUBSTR(v, 1,4),0,'','조')
|| SUBSTR(v, 5,1)||DECODE(SUBSTR(v, 5,1),0,'','천')
|| SUBSTR(v, 6,1)||DECODE(SUBSTR(v, 6,1),0,'','백')
|| SUBSTR(v, 7,1)||DECODE(SUBSTR(v, 7,1),0,'','십')
|| SUBSTR(v, 8,1)||DECODE(SUBSTR(v, 5,4),0,'','억')
|| SUBSTR(v, 9,1)||DECODE(SUBSTR(v, 9,1),0,'','천')
|| SUBSTR(v,10,1)||DECODE(SUBSTR(v,10,1),0,'','백')
|| SUBSTR(v,11,1)||DECODE(SUBSTR(v,11,1),0,'','십')
|| SUBSTR(v,12,1)||DECODE(SUBSTR(v, 9,4),0,'','만')
|| SUBSTR(v,13,1)||DECODE(SUBSTR(v,13,1),0,'','천')
|| SUBSTR(v,14,1)||DECODE(SUBSTR(v,14,1),0,'','백')
|| SUBSTR(v,15,1)||DECODE(SUBSTR(v,15,1),0,'','십')
|| SUBSTR(v,16,1)
, '1234567890', '일이삼사오육칠팔구') v
FROM (SELECT amt, LPAD(amt,16,'0') v FROM t)
;
[정답보기 - 정규식] <=== 트리플클릭
SELECT amt,
TRANSLATE(
REGEXP_REPLACE(
REGEXP_REPLACE(
REGEXP_REPLACE(
LPAD(amt,16,'0')
, '(.)(.)(.)(.)', '\1천\2백\3십\4 ')
, '(.*) (.*) (.*) (.*) ', '\1조\2억\3만\4')
, '0천0백0십0.|0[천백십]', '')
, '1234567890', '일이삼사오육칠팔구') v
FROM t
;