77百科网
当前位置: 首页 生活百科

oracle将表字段转为小写(Oracle实现金额小写转大写函数)

时间:2023-08-07 作者: 小编 阅读量: 1 栏目名: 生活百科

oracle将表字段转为小写?

oracle将表字段转为小写?函数代码:create or replace function F_upper_money(p_num in number default null)return nvarchar2 is/*Ver:1.0 Created By xsb on 2003-8-18 For:将金额数字(单位元)转换为大写(采用从低至高算法)数字整数部分不得超过16位,可以是负数Ver:1.1 Modified By xsb on 2003-8-20 For:个位数处理也放在For循环中Ver:1.2 Modified By xsb on 2003-8-22 For:分后不带整字Ver:1.3 Modified By xsb on 2003-8-28 For:完善测试用例测试用例:SET HEAD OFFSET FEED OFFselect '无参数时='||f_upper_money() from dual;select 'null='||f_upper_money(null) from dual;select '0='||f_upper_money(0) from dual;select '0.01='||f_upper_money(0.01) from dual;select '0.126='||f_upper_money(0.126) from dual;select '01.234='||f_upper_money(01.234) from dual;select '10='||f_upper_money(10) from dual;select '100.1='||f_upper_money(100.1) from dual;select '100.01='||f_upper_money(100.01) from dual;select '10000='||f_upper_money(10000) from dual;select '10012.12='||f_upper_money(10012.12) from dual;select '20000020.01='||f_upper_money(20000020.01) from dual;select '3040506708.901='||f_upper_money(3040506708.901) from dual;select '40005006078.001='||f_upper_money(40005006078.001) from dual;select '-123456789.98='||f_upper_money(-123456789.98) from dual;select '123456789123456789.89='||f_upper_money(123456789123456789.89) from dual;*/Result nvarchar2(100);--返回字符串num_round nvarchar2(100) :=to_char(abs(round(p_num,2)));--转换数字为小数点后2位的字符(正数)num_left nvarchar2(100);--小数点左边的数字num_right nvarchar2(2);--小数点右边的数字str1 nchar(10) :='零壹贰参肆伍陆柒捌玖';--数字大写str2 nchar(16) :='元拾佰仟万拾佰仟亿拾佰仟万拾佰仟';--数字位数(从低至高)num_pre number(1):=1;--前一位上的数字num_current number(1);--当前位上的数字num_count number:=0;--当前数字位数beginif p_num is null then return null;end if;--转换数字为null时返回nullselect to_char(nvl(substr(to_char(num_round),1,decode(instr(to_char(num_round),'.'),0,length(num_round),instr(to_char(num_round),'.')-1)),0)) into num_left from dual;--取得小数点左边的数字select substr(to_char(num_round),decode(instr(to_char(num_round),'.'),0,length(num_round) 1,instr(to_char(num_round),'.') 1),2)into num_right from dual;--取得小数点右边的数字if length(num_left)>16 then return '**********'; end if;--数字整数部分超过16位时--采用从低至高的算法,先处理小数点右边的数字if length(num_right)=2 thenif to_number(substr(num_right,1,1))=0 thenresult:='零'||substr(str1,to_number(substr(num_right,2,1)) 1,1)||'分';elseresult:=substr(str1,to_number(substr(num_right,1,1)) 1,1)||'角'||substr(str1,to_number(substr(num_right,2,1)) 1,1)||'分';end if;elsif length(num_right)=1 thenresult:=substr(str1,to_number(substr(num_right,1,1)) 1,1)||'角整';elseresult :='整';end if;--再处理小数点左边的数字for i in reverse 1..length(num_left)loop --(从低至高)num_count:=num_count 1;--当前数字位数num_current:=to_number(substr(num_left,i,1));--当前位上的数字if num_current>0 then --当前位上数字不为0按正常处理result:=substr(str1,num_current 1,1)||substr(str2,num_count,1)||result;else --当前位上数字为0时if mod(num_count-1,4)=0 then --当前位是元、万或亿时result:=substr(str2,num_count,1)||result;num_pre:=0;--元、万,亿前不准加零end if;ifnum_pre>0 or length(num_left)=1 then--上一位数字不为0或只有个位时result:=substr(str1,num_current 1,1)||result;end if;end if;num_pre:=num_current;end loop;if p_num<0 then --转换数字是负数时result:='负'||result;end if;return Result;exceptionwhen othersthenraise_application_error(-20001,'数字转换大写出现错误'||sqlerrm);end ;,今天小编就来聊一聊关于oracle将表字段转为小写?接下来我们就一起去研究一下吧!

oracle将表字段转为小写

函数代码:

create or replace function F_upper_money(p_num in number default null)return nvarchar2 is/*Ver:1.0 Created By xsb on 2003-8-18 For:将金额数字(单位元)转换为大写(采用从低至高算法)数字整数部分不得超过16位,可以是负数。Ver:1.1 Modified By xsb on 2003-8-20 For:个位数处理也放在For循环中。Ver:1.2 Modified By xsb on 2003-8-22 For:分后不带整字。Ver:1.3 Modified By xsb on 2003-8-28 For:完善测试用例。测试用例:SET HEAD OFFSET FEED OFFselect '无参数时='||f_upper_money() from dual;select 'null='||f_upper_money(null) from dual;select '0='||f_upper_money(0) from dual;select '0.01='||f_upper_money(0.01) from dual;select '0.126='||f_upper_money(0.126) from dual;select '01.234='||f_upper_money(01.234) from dual;select '10='||f_upper_money(10) from dual;select '100.1='||f_upper_money(100.1) from dual;select '100.01='||f_upper_money(100.01) from dual;select '10000='||f_upper_money(10000) from dual;select '10012.12='||f_upper_money(10012.12) from dual;select '20000020.01='||f_upper_money(20000020.01) from dual;select '3040506708.901='||f_upper_money(3040506708.901) from dual;select '40005006078.001='||f_upper_money(40005006078.001) from dual;select '-123456789.98='||f_upper_money(-123456789.98) from dual;select '123456789123456789.89='||f_upper_money(123456789123456789.89) from dual;*/Result nvarchar2(100);--返回字符串num_round nvarchar2(100) :=to_char(abs(round(p_num,2)));--转换数字为小数点后2位的字符(正数)num_left nvarchar2(100);--小数点左边的数字num_right nvarchar2(2);--小数点右边的数字str1 nchar(10) :='零壹贰参肆伍陆柒捌玖';--数字大写str2 nchar(16) :='元拾佰仟万拾佰仟亿拾佰仟万拾佰仟';--数字位数(从低至高)num_pre number(1):=1;--前一位上的数字num_current number(1);--当前位上的数字num_count number:=0;--当前数字位数beginif p_num is null then return null;end if;--转换数字为null时返回nullselect to_char(nvl(substr(to_char(num_round),1,decode(instr(to_char(num_round),'.'),0,length(num_round),instr(to_char(num_round),'.')-1)),0)) into num_left from dual;--取得小数点左边的数字select substr(to_char(num_round),decode(instr(to_char(num_round),'.'),0,length(num_round) 1,instr(to_char(num_round),'.') 1),2)into num_right from dual;--取得小数点右边的数字if length(num_left)>16 then return '**********'; end if;--数字整数部分超过16位时--采用从低至高的算法,先处理小数点右边的数字if length(num_right)=2 thenif to_number(substr(num_right,1,1))=0 thenresult:='零'||substr(str1,to_number(substr(num_right,2,1)) 1,1)||'分';elseresult:=substr(str1,to_number(substr(num_right,1,1)) 1,1)||'角'||substr(str1,to_number(substr(num_right,2,1)) 1,1)||'分';end if;elsif length(num_right)=1 thenresult:=substr(str1,to_number(substr(num_right,1,1)) 1,1)||'角整';elseresult :='整';end if;--再处理小数点左边的数字for i in reverse 1..length(num_left)loop --(从低至高)num_count:=num_count 1;--当前数字位数num_current:=to_number(substr(num_left,i,1));--当前位上的数字if num_current>0 then --当前位上数字不为0按正常处理result:=substr(str1,num_current 1,1)||substr(str2,num_count,1)||result;else --当前位上数字为0时if mod(num_count-1,4)=0 then --当前位是元、万或亿时result:=substr(str2,num_count,1)||result;num_pre:=0;--元、万,亿前不准加零end if;ifnum_pre>0 or length(num_left)=1 then--上一位数字不为0或只有个位时result:=substr(str1,num_current 1,1)||result;end if;end if;num_pre:=num_current;end loop;if p_num<0 then --转换数字是负数时result:='负'||result;end if;return Result;exceptionwhen othersthenraise_application_error(-20001,'数字转换大写出现错误!'||sqlerrm);end ;

测试用例:

-- 无参数,结果为:null=select 'null='||f_upper_money(null) total from dual;-- 0=零元整select '0='||f_upper_money(0) total from dual;-- 0.05=零元零伍分select '0.05='||f_upper_money(0.05) total from dual;-- 0.155=零元壹角陆分select '0.155='||f_upper_money(0.155) total from dual;-- 01.125=壹元壹角参分select '01.125='||f_upper_money(01.125) total from dual;-- 10=壹拾元整select '10='||f_upper_money(10) total from dual;-- 100.5=壹佰元伍角整select '100.5='||f_upper_money(100.5) total from dual;-- 100.05=壹佰元零伍分select '100.05='||f_upper_money(100.05) from dual;-- 10000=壹万元整select '10000='||f_upper_money(10000) from dual;-- 10025.52=壹万零贰拾伍元伍角贰分select '10025.52='||f_upper_money(10025.52) from dual;-- 50000020.05=伍仟万零贰拾元零伍分select '50000020.05='||f_upper_money(50000020.05) from dual;-- 5040302105.501=伍拾亿肆仟零参拾万贰仟壹佰零伍元伍角整select '5040302105.501='||f_upper_money(5040302105.501) from dual;-- 50002001075.001=伍佰亿零贰佰万壹仟零柒拾伍元整select '50002001075.001='||f_upper_money(50002001075.001) from dual;-- -123456789.15=负壹亿贰仟参佰肆拾伍万陆仟柒佰捌拾玖元壹角伍分select '-123456789.15='||f_upper_money(-123456789.15) from dual;-- 123456789123456789.89=**********select '123456789123456789.89='||f_upper_money(123456789123456789.89) from dual;

    推荐阅读
  • 苹果手机怎么和ipad同步 苹果手机怎么和ipad同步照片

    7、打开“iMessage”,在信息设置下,打开“iMessage”按键,这样可开启iMessage功能。

  • 梦见水灾暗示什么(梦见水灾有啥预示)

    我们一起去了解并探讨一下这个问题吧!梦见罕见的水灾,预示你可能会遭敌手的反击,需要小心防范。已婚女子梦见水灾,提醒你注意子宫疾病。男性老年人梦见水灾,会平静离开人世。未婚姑娘梦见发生水灾,父母会同意她与心上人结婚。

  • 枇杷树一般就是几月份栽种(枇杷树挂果时间要了解)

    枇杷树栽种范围很广泛,不仅是因为它极高的观赏性,被用作园林,街道,居住区的绿化,它的果实就是枇杷,还具有清肺止咳的神奇功效,因此深受人们的喜爱。枇杷树种一般不分雌雄,人们可以自行播种,移栽,嫁接等等。枇杷树生长适合温度在十二摄氏度以上的环境,冬季不能低于零下五度,幼果期是比较关键的,不能低于零摄氏度,否则幼果会停止生长,或者造成早衰,落果现象。枇杷树原产地在亚热带地区,是一种亚热带水果树。

  • 苹果mac财报(三季度笔记本电脑销量同比下降)

    IT之家11月3日消息,市场研究机构StrategyAnalytics今日公布了2022年第三季度的笔记本市场数据。2022年第三季度笔记本市场前三名分别为联想、惠普、戴尔,市场份额分别为23%、17%、16%。此外,大多数厂商的销量都同比下跌,只有苹果MacBook增长了26%,三季度销量达到810万台,份额达到了14%。

  • 野蜂蛰了肿不大(天热蜂伤人病情增多)

    近些天,常州四院连续收治了多名被蜂蛰伤后出现心慌、胸闷等不适,其中一例送到医院急诊的时候,已经处于休克状态,医生诊断为过敏性休克,经过抢救后才转危为安。部分人对蜂毒过敏,可引起荨麻疹、鼻炎、唇及眼睑肿胀、腹痛、腹泻、恶心、呕吐,严重者可导致喉头水肿而出现呼吸困难,甚至会出现过敏性休克。所以,如被蜂蛰伤后出现头疼、头昏、恶心、呕吐、烦躁、面色苍白、心悸、胸闷等症状时,应立即到医院治疗。

  • 新历是指什么(新历是什么意思)

    以下内容希望对你有帮助!新历是指什么新历一般指公元,即公历纪年法,是一种源自于西方社会的纪年方法。原称基督纪元,又称西历或西元,是由意大利医生兼哲学家AloysiusLilius对儒略历加以改革而制成的一种历法——《格里历》。公历纪年以耶稣诞生之年作为纪年的开始。在儒略历与格里高利历中,在耶稣诞生之后的日期,称为主的年份AnnoDomini(拉丁)。而在耶稣诞生之前,称为主前BeforeChrist。

  • 李立功名字打分97分

    文章目录:一、李立功相关名字打分97二、李立功相关名字评分109三、李立功相关名字推荐四、李立功相关名字大全五、其他人还看了一、李立功相关名字打分97李庆太李慧佳李秀花李珊儿李仙月李昭明李采薇李秋阳李培禹李熠霖李虹霖李思进李邦邦李仕华李春霖李二根李旭涛李天路李士珍李懋扬李兴勇李龙大李贤忠李璐李依晓李舒桐李从佳李瑞芬李洹李海霞李学宏李洁人李先明李宇豪李筱英李二狗李爱琴李利生李星潭李洪森李涵嫣李春青李

  • 河南矿山开工招聘电话被打爆(河南矿山起重最新招聘)

    过年前,河南省矿山起重机有限公司火了,原因就是羡煞旁人的年终奖。在腊月二十六的年会上,公司40多位员工现场领取了6100万元奖金,每人都是100万元以上,其中3人均拿到了最高的500万元奖金。后来公司还回应解释,有的销售人员去年业绩达到了3个多亿。这也不难解释,在正月初六开工后,该公司咨询、招聘的电话被打爆了。有媒体了解到,截至目前,网上咨询人数超三百人,到公司现场填报详细信息的超四十人。

  • 百合花的花语及含义(香水百合花的寓意和花语是什么)

    香水百合的花语有:伟大的爱、永不磨灭的爱情、永恒的美、心心相印、荣誉胜利、财富高贵等。她又叫天上百合、卡萨布兰卡,其花瓣纯洁无斑点,地下鳞茎白色,花期6月-7月,花单生或簇生。花朵硕大,形状为钟形或漏斗形。

  • 母乳减少原因 母乳减少的原因

    乳腺阻塞发生时,仍要持续亲喂你的母奶,停喂母奶可能造成乳汁淤积过久产生脓包,产生乳腺炎。乳腺炎期间仍然可以哺育母乳,但有些妈妈并不喜欢或感觉不妥,有些妈咪会暂时停喂母奶,导致你的母奶供应下降。