CREATE OR REPLACE FUNCTION printMoneylnZh(money number) RETURN VARCHAR2 IS
TYPE type_varchar2 is table of VARCHAR2(500);
m_string type_varchar2 := type_varchar2('分','角','圆','拾','佰','仟','','拾','佰','仟','','拾','佰','仟');
n_string type_varchar2 := type_varchar2('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
v_num NUMBER := 0;
f_money NUMBER;
int_money NUMBER;
money_length NUMBER;
f_money_length NUMBER;
money_chinese varchar2(10000) default null;
type n_table is table of NUMBER index by binary_integer;
n_money n_table;
BEGIN
select (money - floor(money))*100, trunc(money)
INTO f_money, int_money
from dual;
money_length := length(int_money);
select length(money) - money_length - 1 into f_money_length from dual;
IF f_money = 0 THEN
FOR i in reverse 1 .. money_length loop
v_num := v_num + 1;
SELECT trunc(int_money / power(10,i - 1), 0)
INTO n_money(v_num)
FROM dual;
IF n_money(v_num) = 0 THEN
IF substr(money_chinese, length(money_chinese), 1) != '零' THEN
money_chinese := money_chinese || n_string(n_money(v_num) + 1);
END IF;
else
money_chinese := money_chinese || n_string(n_money(v_num) + 1) ||
m_string(2 + i);
end if;
if i=9 then
money_chinese := rtrim(money_chinese, '零');
money_chinese := money_chinese ||'亿';
elsif i=5 then
money_chinese := rtrim(money_chinese, '零');
IF substr(money_chinese, length(money_chinese), 1) != '亿' THEN
money_chinese := money_chinese ||'万';
end if;
end if;
int_money := int_money - power(10, i - 1) * n_money(v_num);
end loop;
money_chinese := rtrim(money_chinese, '零') || '整';
dbms_output.put_line(money_chinese);
else
FOR i in reverse 1 .. money_length loop
v_num := v_num + 1;
SELECT trunc(int_money / power(10, i - 1), 0)
INTO n_money(v_num)
FROM dual;
IF n_money(v_num) = 0 THEN
IF substr(money_chinese, length(money_chinese), 1) != '零' THEN
money_chinese := money_chinese || n_string(n_money(v_num) + 1);
END IF;
else
money_chinese := money_chinese || n_string(n_money(v_num) + 1) ||
m_string(2 + i);
end if;
if i=9 then
money_chinese := rtrim(money_chinese, '零');
money_chinese := money_chinese ||'亿';
elsif i=5 then
money_chinese := rtrim(money_chinese, '零');
IF substr(money_chinese, length(money_chinese), 1) != '亿' THEN
money_chinese := money_chinese ||'万';
end if;
end if;
int_money := int_money - power(10, i - 1) * n_money(v_num);
end loop;
if f_money<10 then
money_chinese:=money_chinese||n_string(f_money+1)||'分';
else
if mod(f_money,10)=0 then
money_chinese:=money_chinese||n_string(f_money/10+1)||'角';
else
v_num:=0;
for i in reverse 1..f_money_length loop
v_num:=v_num+1;
SELECT trunc(f_money/power(10,i-1),0)INTO n_money(v_num) from dual;
money_chinese:=money_chinese||n_string(n_money(v_num)+1)||m_string(i);
f_money:=f_money-power(10,i-1)*n_money(v_num);
end loop;
end if;
end if;
end if;
RETURN money_chinese;
END;
TYPE type_varchar2 is table of VARCHAR2(500);
m_string type_varchar2 := type_varchar2('分','角','圆','拾','佰','仟','','拾','佰','仟','','拾','佰','仟');
n_string type_varchar2 := type_varchar2('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
v_num NUMBER := 0;
f_money NUMBER;
int_money NUMBER;
money_length NUMBER;
f_money_length NUMBER;
money_chinese varchar2(10000) default null;
type n_table is table of NUMBER index by binary_integer;
n_money n_table;
BEGIN
select (money - floor(money))*100, trunc(money)
INTO f_money, int_money
from dual;
money_length := length(int_money);
select length(money) - money_length - 1 into f_money_length from dual;
IF f_money = 0 THEN
FOR i in reverse 1 .. money_length loop
v_num := v_num + 1;
SELECT trunc(int_money / power(10,i - 1), 0)
INTO n_money(v_num)
FROM dual;
IF n_money(v_num) = 0 THEN
IF substr(money_chinese, length(money_chinese), 1) != '零' THEN
money_chinese := money_chinese || n_string(n_money(v_num) + 1);
END IF;
else
money_chinese := money_chinese || n_string(n_money(v_num) + 1) ||
m_string(2 + i);
end if;
if i=9 then
money_chinese := rtrim(money_chinese, '零');
money_chinese := money_chinese ||'亿';
elsif i=5 then
money_chinese := rtrim(money_chinese, '零');
IF substr(money_chinese, length(money_chinese), 1) != '亿' THEN
money_chinese := money_chinese ||'万';
end if;
end if;
int_money := int_money - power(10, i - 1) * n_money(v_num);
end loop;
money_chinese := rtrim(money_chinese, '零') || '整';
dbms_output.put_line(money_chinese);
else
FOR i in reverse 1 .. money_length loop
v_num := v_num + 1;
SELECT trunc(int_money / power(10, i - 1), 0)
INTO n_money(v_num)
FROM dual;
IF n_money(v_num) = 0 THEN
IF substr(money_chinese, length(money_chinese), 1) != '零' THEN
money_chinese := money_chinese || n_string(n_money(v_num) + 1);
END IF;
else
money_chinese := money_chinese || n_string(n_money(v_num) + 1) ||
m_string(2 + i);
end if;
if i=9 then
money_chinese := rtrim(money_chinese, '零');
money_chinese := money_chinese ||'亿';
elsif i=5 then
money_chinese := rtrim(money_chinese, '零');
IF substr(money_chinese, length(money_chinese), 1) != '亿' THEN
money_chinese := money_chinese ||'万';
end if;
end if;
int_money := int_money - power(10, i - 1) * n_money(v_num);
end loop;
if f_money<10 then
money_chinese:=money_chinese||n_string(f_money+1)||'分';
else
if mod(f_money,10)=0 then
money_chinese:=money_chinese||n_string(f_money/10+1)||'角';
else
v_num:=0;
for i in reverse 1..f_money_length loop
v_num:=v_num+1;
SELECT trunc(f_money/power(10,i-1),0)INTO n_money(v_num) from dual;
money_chinese:=money_chinese||n_string(n_money(v_num)+1)||m_string(i);
f_money:=f_money-power(10,i-1)*n_money(v_num);
end loop;
end if;
end if;
end if;
RETURN money_chinese;
END;