-----------------------------------------------------------------------
-- 숫자를 한글로 표기하는 Function
-----------------------------------------------------------------------
CREATE OR REPLACE FUNCTION f_Num2Hangul( Number_In Number, Type_IN VARCHAR2 )
RETURN VARCHAR2 IS Return_Val VARCHAR2(62);
Curr_Val VARCHAR2(20);
i number;
j number;
Zero_Skip varchar(1);
strNum Varchar(1);
BEGIN
return_Val := '';
Curr_Val := '';
strNum := '';
if Number_In > 0 then
Curr_Val := ltrim(rtrim(replace(to_char(Number_In),',','')));
i := Lengthb(Curr_Val);
j := Lengthb(Curr_Val);
loop
Zero_Skip := 'N';
strNum := substrb(Curr_Val,j-(i-1),1);
if (strNum >= '1') and (strNum <= '9') then
if strNum = '1' then Return_Val := Return_Val || '일'; end if ;
if strNum = '2' then Return_Val := Return_Val || '이'; end if ;
if strNum = '3' then Return_Val := Return_Val || '삼'; end if ;
if strNum = '4' then Return_Val := Return_Val || '사'; end if ;
if strNum = '5' then Return_Val := Return_Val || '오'; end if ;
if strNum = '6' then Return_Val := Return_Val || '육'; end if ;
if strNum = '7' then Return_Val := Return_Val || '칠'; end if ;
if strNum = '8' then Return_Val := Return_Val || '팔'; end if ;
if strNum = '9' then Return_Val := Return_Val || '구'; end if ;
else
Zero_Skip := 'Y';
end if;
if Zero_Skip = 'N' then
if i = 2 then Return_Val := Return_Val || '십'; end if ;
if i = 3 then Return_Val := Return_Val || '백'; end if ;
if i = 4 then Return_Val := Return_Val || '천'; end if ;
if i = 5 then Return_Val := Return_Val || '만'; end if ;
if i = 6 then
if to_number(substrb(Curr_Val,j-(i-2),1)) = 0 then
Return_Val := Return_Val || '십만';
else
Return_Val := Return_Val || '십';
end if;
end if;
if i = 7 then
if (to_number(nvl(substrb(Curr_Val,j-(i-2),1),'0')) <= 0) and
(to_number(nvl(substrb(Curr_Val,j-(i-3),1),'0')) <= 0) then
Return_Val := Return_Val || '백만';
else
Return_Val := Return_Val || '백';
end if;
end if;
if i = 8 then
if (to_number(nvl(substrb(Curr_Val,j-(i-2),1),'0')) <= 0) and
(to_number(nvl(substrb(Curr_Val,j-(i-3),1),'0')) <= 0) and
(to_number(nvl(substrb(Curr_Val,j-(i-4),1),'0')) <= 0) then
Return_Val := Return_Val || '천만';
else
Return_Val := Return_Val || '천';
end if;
end if;
if i = 9 then Return_Val := Return_Val || '억'; end if ;
if i = 10 then
if to_number(substrb(Curr_Val,j-(i-2),1)) = 0 then
Return_Val := Return_Val || '십억';
else
Return_Val := Return_Val || '십';
end if;
end if;
if i = 11 then
if (to_number(nvl(substrb(Curr_Val,j-(i-2),1),'0')) <= 0) and
(to_number(nvl(substrb(Curr_Val,j-(i-3),1),'0')) <= 0) then
Return_Val := Return_Val || '백억';
else
Return_Val := Return_Val || '백';
end if;
end if;
if i = 12 then
if (to_number(nvl(substrb(Curr_Val,j-(i-2),1),'0')) <= 0) and
(to_number(nvl(substrb(Curr_Val,j-(i-3),1),'0')) <= 0) and
(to_number(nvl(substrb(Curr_Val,j-(i-4),1),'0')) <= 0) then
Return_Val := Return_Val || '천억';
else
Return_Val := Return_Val || '천';
end if;
end if;
if i = 13 then Return_Val := Return_Val || '조'; end if ;
if i = 14 then
if to_number(substrb(Curr_Val,j-(i-2),1)) = 0 then
Return_Val := Return_Val || '십조';
else
Return_Val := Return_Val || '십';
end if;
end if;
if i = 15 then
if (to_number(nvl(substrb(Curr_Val,j-(i-2),1),'0')) <= 0) and
(to_number(nvl(substrb(Curr_Val,j-(i-3),1),'0')) <= 0) then
Return_Val := Return_Val || '백조';
else
Return_Val := Return_Val || '백';
end if;
end if;
if i = 16 then
if (to_number(nvl(substrb(Curr_Val,j-(i-2),1),'0')) <= 0) and
(to_number(nvl(substrb(Curr_Val,j-(i-3),1),'0')) <= 0) and
(to_number(nvl(substrb(Curr_Val,j-(i-4),1),'0')) <= 0) then
Return_Val := Return_Val || '천조';
else
Return_Val := Return_Val || '천';
end if;
end if;
if i > 16 then Return_Val := Return_Val || ''; end if;
end if;
i := i - 1;
If i = 0 Then EXIT; end if;
end loop;
end if;
if Type_In = '1' then Return_Val := Return_Val || '원'; end if;
if Type_In = '2' then Return_Val := '금 ' || Return_Val || ' 원정'; end if;
Return Return_Val;
end;
/
DB Link 방법 (0) | 2012.05.21 |
---|---|
힌트 사용 방법 (0) | 2012.05.21 |
계층형 데이타 Query (0) | 2012.05.18 |
테이블 함수 예제 2 (0) | 2012.05.18 |
문자열 수식을 입력받아 계산된 값 리턴. (0) | 2012.05.18 |