27,579
社区成员
发帖
与我相关
我的任务
分享
SQL>
SQL> create or replace function fn(v_in varchar2)
2 return varchar
3 as
4 v_ret varchar2(30);
5 begin
6 v_ret := translate(v_in, '0123456789','零一二三四五六七八九');
7 if length(v_ret) = 2 then
8 v_ret := substr(v_ret,1,1) || '十' || substr(v_ret,2,1);
9 v_ret := trim(leading '一' from trim(trailing '零' from v_ret));
10 end if;
11 return v_ret;
12 end;
13 /
Function created
SQL> select fn(1992) from dual
2 union all
3 select fn(2) from dual
4 union all
5 select fn(10) from dual
6 union all
7 select fn(15) from dual
8 union all
9 select fn(20) from dual
10 union all
11 select fn(21) from dual
12 union all
13 select fn(25) from dual;
FN(1992)
--------------------------------------------------------------------------------
一九九二
二
十
十五
二十
二十一
二十五
7 rows selected
SQL> drop function fn;
Function dropped
SQL>