`

如何在ORACLE中實現人民幣大寫的轉換-数据库专栏,ORACLE

阅读更多

create or replace function dx_money
(
money in number
)
return varchar2 as v_money varchar2(150);
rv_money0 varchar2(20);
rv_money1 varchar2(4);
rv_money2 varchar2(4);
v_money0 varchar2(20);
v_money1 varchar2(4);
v_money2 varchar2(4);
v_money3 varchar2(4);
v_money4 varchar2(4);
v_money5 varchar2(4);
v_money6 varchar2(4);
v_money7 varchar2(4);
v_money8 varchar2(4);
v_money9 varchar2(4);
v_money10 varchar2(4);
v_money11 varchar2(4);
v_money12 varchar2(4);
rpv_money1 varchar2(4);
rpv_money2 varchar2(4);
pv_money0 varchar2(14);
pv_money1 varchar2(4);
pv_money2 varchar2(4);
pv_money3 varchar2(4);
pv_money4 varchar2(4);
pv_money5 varchar2(4);
pv_money6 varchar2(4);
pv_money7 varchar2(4);
pv_money8 varchar2(4);
pv_money9 varchar2(4);
pv_money10 varchar2(4);
pv_money11 varchar2(4);
pv_money12 varchar2(4);

begin
 v_money0:=ltrim(rtrim(to_char(floor(money))));
 rv_money0:=ltrim(rtrim(to_char(floor(money*100))));
 rv_money1:=substr(rv_money0,length(rv_money0),1);
 if length(rv_money0)>1 then
 rv_money2:=substr(rv_money0,length(rv_money0)-1,1);
 else
   rv_money2:=0;
 end if;
   v_money1:=substr(v_money0,length(v_money0),1);
  if length(v_money0)-1>0 then
      v_money2:=substr(v_money0,length(v_money0)-1,1);
   else v_money2:=0;
   end if;
  if length(v_money0)-2>0 then
      v_money3:=substr(v_money0,length(v_money0)-2,1);
   else v_money3:=0;
   end if;
  if length(v_money0)-3>0 then
      v_money4:=substr(v_money0,length(v_money0)-3,1);
   else v_money4:=0;
   end if;
  if length(v_money0)-4>0 then
      v_money5:=substr(v_money0,length(v_money0)-4,1);
   else v_money5:=0;
   end if;
  if length(v_money0)-5>0 then
      v_money6:=substr(v_money0,length(v_money0)-5,1);
   else v_money6:=0;
   end if;
  if length(v_money0)-6>0 then
      v_money7:=substr(v_money0,length(v_money0)-6,1);
   else v_money7:=0;
   end if;
  if length(v_money0)-7>0 then
      v_money8:=substr(v_money0,length(v_money0)-7,1);
   else v_money8:=0;
   end if;
  if length(v_money0)-8>0 then
      v_money9:=substr(v_money0,length(v_money0)-8,1);
   else v_money9:=0;
   end if;
  if length(v_money0)-9>0 then
      v_money10:=substr(v_money0,length(v_money0)-9,1);
   else v_money10:=0;
   end if;
  if length(v_money0)-10>0 then
      v_money11:=substr(v_money0,length(v_money0)-10,1);
   else v_money11:=0;
   end if;
  if length(v_money0)-11>0 then
      v_money12:=substr(v_money0,length(v_money0)-11,1);
   else v_money12:=0;
   end if;

select decode(rv_money1,0,'零分',1,'壹分',2,'贰分',3,'叁分',4,'肆分',5,'伍分',
      6,'陆分',7,'柒分',8,'捌分',9,'玖分') into rpv_money1 from dual;
select decode(rv_money2,0,'零角',1,'壹角',2,'贰角',3,'叁角',4,'肆角',5,'伍角',
      6,'陆角',7,'柒角',8,'捌角',9,'玖角') into rpv_money2 from dual;
select decode(v_money1,0,'元',1,'壹元',2,'贰元',3,'叁元',4,'肆元',5,'伍元',
      6,'陆元',7,'柒元',8,'捌元',9,'玖') into pv_money1 from dual;
select decode(v_money2,0,'',1,'壹拾',2,'贰拾',3,'叁拾',4,'肆拾',5,'伍拾',
      6,'陆拾',7,'柒拾',8,'捌拾',9,'玖拾') into pv_money2 from dual;
select decode(v_money3,0,'',1,'壹佰',2,'贰佰',3,'叁佰',4,'肆佰',5,'伍佰',
      6,'陆佰',7,'柒佰',8,'捌佰',9,'玖佰') into pv_money3 from dual;
select decode(v_money4,0,'',1,'壹仟',2,'贰仟',3,'叁仟',4,'肆仟',5,'伍仟',
      6,'陆仟',7,'柒仟',8,'捌仟',9,'玖') into pv_money4 from dual;
select decode(v_money5,0,'',1,'壹万',2,'贰万',3,'叁万',4,'肆万',5,'伍万',
      6,'陆万',7,'柒万',8,'捌万',9,'玖万') into pv_money5 from dual;
select decode(v_money6,0,'',1,'壹拾',2,'贰拾',3,'叁拾',4,'肆拾',5,'伍拾',
      6,'陆拾',7,'柒拾',8,'捌拾',9,'玖拾') into pv_money6 from dual;
select decode(v_money7,0,'',1,'壹佰',2,'贰佰',3,'叁佰',4,'肆佰',5,'伍佰',
      6,'陆佰',7,'柒佰',8,'捌佰',9,'玖佰') into pv_money7 from dual;
select decode(v_money8,0,'',1,'壹仟',2,'贰仟',3,'叁仟',4,'肆仟',5,'伍仟',
      6,'陆仟',7,'柒仟',8,'捌仟',9,'玖仟') into pv_money8 from dual;
select decode(v_money9,0,'',1,'壹亿',2,'贰亿',3,'叁亿',4,'肆亿',5,'伍亿',
      6,'陆亿',7,'柒亿',8,'捌亿',9,'玖亿') into pv_money9 from dual;
select decode(v_money10,0,'',1,'壹拾',2,'贰拾',3,'叁拾',4,'肆拾',5,'伍拾',
      6,'陆拾',7,'柒拾',8,'捌拾',9,'玖拾') into pv_money10 from dual;
select decode(v_money11,0,'',1,'壹佰',2,'贰佰',3,'叁佰',4,'肆佰',5,'伍佰',
      6,'陆佰',7,'柒佰',8,'捌佰',9,'玖佰') into pv_money11 from dual;
select decode(v_money12,0,'',1,'壹仟',2,'贰仟',3,'叁仟',4,'肆仟',5,'伍仟',
      6,'陆仟',7,'柒仟',8,'捌仟',9,'玖仟') into pv_money12 from dual;
  v_money:=pv_money12||pv_money11||pv_money10||pv_money9||pv_money8||
          pv_money7||pv_money6||pv_money5||pv_money4||pv_money3||pv_money2||pv_money1||
          rpv_money2||rpv_money1;
 return (v_money);
end;

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics