---
title: "如何在ORACLE中實現人民幣大寫的轉換-数据库专栏,ORACLE"
author: "lanxing"
date: "2010-07-13T13:54:07Z"
tags: []
categories: ["数据库"]
slug: "oracle-oracle"
draft: false
lastmod: "2010-07-13T14:43:06Z"
id: 711533
url: "https://lanxing.iteye.com/blog/711533"
---

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)&gt;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&gt;0 then  
      v\_money2:=substr(v\_money0,length(v\_money0)-1,1);  
   else v\_money2:=0;  
   end if;  
  if length(v\_money0)-2&gt;0 then  
      v\_money3:=substr(v\_money0,length(v\_money0)-2,1);  
   else v\_money3:=0;  
   end if;  
  if length(v\_money0)-3&gt;0 then  
      v\_money4:=substr(v\_money0,length(v\_money0)-3,1);  
   else v\_money4:=0;  
   end if;  
  if length(v\_money0)-4&gt;0 then  
      v\_money5:=substr(v\_money0,length(v\_money0)-4,1);  
   else v\_money5:=0;  
   end if;  
  if length(v\_money0)-5&gt;0 then  
      v\_money6:=substr(v\_money0,length(v\_money0)-5,1);  
   else v\_money6:=0;  
   end if;  
  if length(v\_money0)-6&gt;0 then  
      v\_money7:=substr(v\_money0,length(v\_money0)-6,1);  
   else v\_money7:=0;  
   end if;  
  if length(v\_money0)-7&gt;0 then  
      v\_money8:=substr(v\_money0,length(v\_money0)-7,1);  
   else v\_money8:=0;  
   end if;  
  if length(v\_money0)-8&gt;0 then  
      v\_money9:=substr(v\_money0,length(v\_money0)-8,1);  
   else v\_money9:=0;  
   end if;  
  if length(v\_money0)-9&gt;0 then  
      v\_money10:=substr(v\_money0,length(v\_money0)-9,1);  
   else v\_money10:=0;  
   end if;  
  if length(v\_money0)-10&gt;0 then  
      v\_money11:=substr(v\_money0,length(v\_money0)-10,1);  
   else v\_money11:=0;  
   end if;  
  if length(v\_money0)-11&gt;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;