declare
cccc varchar2(30);
nnnn number;
n1 number;
n2 number;
n0 number; --记录数字连续为0的个数,多个连续0转化为大写
--只写一个“零”
i1 number;
begin
--数字小写转大写
nnnn:=:block2.item1; --获取阿拉伯数字(:block2.item1为输入阿拉伯数字的域)
if nnnn is NULL then
nnnn:=0;
end if;
if nnnn<(10**8) then --只转化小于1千万的数
n1:=nnnn;
if nnnn<10000 then --数字小于1万
n0:=0;
for i in reverse 1..4 loop --从大到小循环
n2:=floor(n1/(10**(i-1))); --求整数
n1:=mod(n1,10**(i-1)); --求余数
case n2
when 0 then
if (cccc IS NOT NULL) and (n0=0) and (n1!=0) then --当有第一个0且后面不全是0时,才写“零”
cccc:=cccc||'零';
end if;
n0:=n0+1;
when 1 then cccc:=cccc||'壹';n0:=0;
when 2 then cccc:=cccc||'贰';n0:=0;
when 3 then cccc:=cccc||'叁';n0:=0;
when 4 then cccc:=cccc||'肆';n0:=0;
when 5 then cccc:=cccc||'伍';n0:=0;
when 6 then cccc:=cccc||'陆';n0:=0;
when 7 then cccc:=cccc||'柒';n0:=0;
when 8 then cccc:=cccc||'捌';n0:=0;
when 9 then cccc:=cccc||'玖';n0:=0;
end case;
--2,为每一位数字加权
if n2!=0 then --取得的数字不为0才能加权
case i
when 1 then null;
when 2 then cccc:=cccc||'拾';
when 3 then cccc:=cccc||'百';
when 4 then cccc:=cccc||'千';
--when 5 then cccc:=cccc||'万';
end case;
end if;
end loop;
----大于1万
else
---先转化万位以上的4位
n1:=floor(nnnn/(10**4));
n0:=0;
for i in reverse 1..4 loop --从大到小循环
n2:=floor(n1/(10**(i-1))); --求整数
n1:=mod(n1,10**(i-1)); --求余数
case n2
when 0 then
if (cccc IS NOT NULL) and (n0=0) and (n1!=0) then --当有第一个0且后面不全是0时,才写“零”
cccc:=cccc||'零';
end if;
n0:=n0+1;
when 1 then cccc:=cccc||'壹';n0:=0;
when 2 then cccc:=cccc||'贰';n0:=0;
when 3 then cccc:=cccc||'叁';n0:=0;
when 4 then cccc:=cccc||'肆';n0:=0;
when 5 then cccc:=cccc||'伍';n0:=0;
when 6 then cccc:=cccc||'陆';n0:=0;
when 7 then cccc:=cccc||'柒';n0:=0;
when 8 then cccc:=cccc||'捌';n0:=0;
when 9 then cccc:=cccc||'玖';n0:=0;
end case;
--2,为每一位数字加权
if n2!=0 then --取得的数字不为0才能加权
case i
when 1 then null;
when 2 then cccc:=cccc||'拾';
when 3 then cccc:=cccc||'百';
when 4 then cccc:=cccc||'千';
when 5 then cccc:=cccc||'万';
end case;
end if;
end loop;
cccc:=cccc||'万';
--以万位为界取低5位
n1:=mod(nnnn,10000);
-- if n1<10000 then --万位为0,则加'零'
-- cccc:=cccc||'零';
--end if;
n0:=0;
for i in reverse 1..4 loop --从大到小循环
n2:=floor(n1/(10**(i-1))); --求整数
n1:=mod(n1,10**(i-1)); --求余数
case n2
when 0 then
if (cccc IS NOT NULL) and (n0=0) and (n1!=0) then --当有第一个0且后面不全是0时,才写“零”
cccc:=cccc||'零';
end if;
n0:=n0+1;
when 1 then cccc:=cccc||'壹';n0:=0;
when 2 then cccc:=cccc||'贰';n0:=0;
when 3 then cccc:=cccc||'叁';n0:=0;
when 4 then cccc:=cccc||'肆';n0:=0;
when 5 then cccc:=cccc||'伍';n0:=0;
when 6 then cccc:=cccc||'陆';n0:=0;
when 7 then cccc:=cccc||'柒';n0:=0;
when 8 then cccc:=cccc||'捌';n0:=0;
when 9 then cccc:=cccc||'玖';n0:=0;
end case;
--2,为每一位数字加权
if n2!=0 then --取得的数字不为0才能加权
case i
when 1 then null;
when 2 then cccc:=cccc||'拾';
when 3 then cccc:=cccc||'百';
when 4 then cccc:=cccc||'千';
when 5 then cccc:=cccc||'万';
end case;
end if;
end loop;
end if; --数字小于10万
-------------------------------------------
if cccc IS NOT NULL then
:block2.item2:=cccc;
else
:block2.item2:='零';
end if;
end if;--转化小于1千万数
end;