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;

    推荐阅读
  • 真正喜欢一个人是怎么样的(喜欢一个人是什么样子的)

    喜欢一个人究竟是什么样子的呢?我和他的认识说来简单,不过是宿舍有个新规则,谁脱单了请全宿舍吃饭,而我的室友给我发学校的表白墙里了。是他先加的我,刚开始他套路老套,说他会聊天也差不多是会的,一开始的老大爷治疗脱发给我弄了个措手不及。渐渐的变和他没有了交谈,后天的相熟呢!虽是复杂,但也可总结几字:忘记旧人。没错为了忘记一个略有好感的男生,一个第一次牵手的男生。删他时,恰逢是“删了吧”这首歌最火的时候。

  • 整齐和整整齐齐有什么不同(齐齐整整与整整齐齐的区别)

    3、整整齐齐,汉语成语,拼音:zhěngzhěngqíqí,释义:保持整洁和有条不紊。出自《水浒传》。

  • 无语是什么意思(羊幂无语是什么意思)

    2021年5月5日,#杨幂陈学冬王者朋友局#、#杨幂王者头像#都登上了微博热搜。据悉,号称飞飞公主永不认输的杨幂又来打游戏了,这一次居然还叫上了多年好友陈学冬双排上分!虽然上次飞飞公主输了,但最近也用貂蝉证明了自己。杨幂今天中午发的微博,想欣赏飞飞公主的舞姿吗?也是引发了众多粉丝围观。不知道杨幂最近是不是开始玩起王者荣耀张飞了?

  • 吃汤圆的寓意是什么意思(吃汤圆的意思)

    以下内容大家不妨参考一二希望能帮到您!吃汤圆的寓意是什么意思吃汤圆寓意着:全家人团团圆圆,和睦幸福,同时也寄托了对未来生活的美好愿望。汤圆的名称与“团圆”字音相近,取团圆之意,表达的是人们喜爱阖家团圆的美意,人们也以此怀念离别的亲人,寄托了对未来生活的美好愿望。

  • 冬季运动的好处及注意事项(冬季运动要注意什么)

    各种热身运动为了避免在运动时候发生拉伤、扭伤等。尤其是在冬季,人的肌肉和韧带会反射性地引起血管收缩、黏滞性增加,关节的活动幅度见效,韧带的伸展度降低,如此一来,如果不充分做好热身运动,就会引起关节韧带拉伤、肌肉拉伤等问题。这是因为冬季气候寒冷,爆发性的无氧运动容易引起身体不适。另外锻炼间隙要适当缩短,尽量避免长时间处于冷空气中。

  • 告诉你蜂巢蜜怎么吃(蜂巢蜜的食用方法)

    蜂巢蜜尚未将蜂蜜与巢脾分开,营养物质没有受到影响,在近些年受到了许多爱好蜂蜜的朋友们喜爱。食用蜂巢蜜最简单的方法就是直接吃。在吮食完蜂蜜后,可以将蜂巢充分咀嚼。蜂巢蜜中含有大量的蜂蜜,浸泡在温水中会快速融化,成为营养丰富的蜂蜜水。除此之外,蜂巢蜜还可以夹在面包片中一起食用,可以为早餐添加丰富的营养。

  • 如何让手机当门禁卡(教你一招把门禁卡写进手机)

    第三步、拿出我们的门禁卡,对准手机后面,开启NFC功能。我们在使用门禁卡开门的时候,需要点击开启设置,打开NFC功能,然后添加NFC触碰应用,就能实现碰一碰解开小区大门。NFC功能手机门禁卡能写进手机,源于手机里面的一个功能"NFC",又称"近距离无线通讯技术",可以实现近距离的数据交换,并且速度远远超过蓝牙传输。NFC功能一览公交卡,乘坐公交或者地铁,手机就能支付。

  • 海口严查汽车违章(改装必须安全合法)

    针对小高私自改装面包车的行为,海口公安交警表示,根据我国《道路交通安全法》第十六条第一款规定,任何单位或者个人不得擅自改变机动车已登记的结构、构造或者特征。机动车所有人为两人以上,需要将登记的所有人姓名变更为其他所有人姓名的,可以向登记地车辆管理所申请变更登记。海口公安交警表示,车主对自己的爱车的改装必须在安全、合法的前提下进行。

  • 走读生是什么意思(走读生简介)

    走读生是什么意思走读生是指所念的学校有住宿条件,该学生因为家住的比较近或其它原因,没有选择在学校住宿的学生指对于所填志愿院校,若被录取是否同意以非120住校方式就读。走读生来校上课、参加其他课外活动,但不住校。只要是寄宿制学校就会分走读和住校。一般非寄宿学校学生都是走读的,分为小学至大学不等。走读生可以在学校食宿,同时遵从学校安排。走读还要有一定的规章制度,首先要保证自己的人身安全。

  • 消除鸡皮肤的小诀窍变成大妙招(去鸡皮肤最有效的方法)

    痛经活络,解毒消肿,用丝瓜络洗澡不仅能去除身体污渍和老化角质,还可深层清除油脂,疏通毛孔,长期使用可使皮肤变得光滑细腻。要说去鸡皮肤最有效的产品,当然是最受消费者喜爱的帝草元了。帝草元专注鸡皮肤,根据鸡皮肤的发病机制,采用内修外护、排养并进的修复原理,先去除表皮堆积角质,疏通毛孔,促进汗毛正常生长,使皮肤变得光滑。重启肌肤抵抗力,增强肌肤防御力。