数字转换成英文

今天看到一篇帖子,讲述的是如何把数字转换成英文表示。本人觉得不错,将其收入我的经典sql。原文如下:

利用to_timestamp,to_char两个内置函数将范围为(-999999999,999999999)的数值转换为英文表示:

SELECT initcap(to_char(to_timestamp(substr(lpad(abs(123456789), 9, '0'),
                                           1,
                                           3),
                                    'FF3'),
                       'FFSP') || ' ' ||
               to_char(to_timestamp('000' ||
                                    substr(lpad(abs(123456789), 9, '0'), 4),
                                    'FF9'),
                       'FFSP'))

  FROM dual;

--output
One Hundred Twenty-Three Million Four Hundred Fifty-Six Thousand Seven Hundred Eighty-Nine


利用to_timestamp函数和‘FF3', 'FF9'格式参数将数字格式成微秒的格式(9位), 所以123就变成了123000000。对于此参数的解释如下:

Fractional seconds; no radix character is printed (use the X format element to add the radix character). Use the numbers 1 to 9 after FF to specify the number of digits in the fractional second portion of the datetime value returned. If you do not specify a digit, then Oracle uses the precision specified for the datetime datatype or the datatype's default precision.

Examples: 'HH:MI:SS.FF'

SELECT TO_CHAR(SYSTIMESTAMP, 'SS.FF3') from dual;


然后就是使用to_char的SP参数了。SP顾名思义就是spell out(读出),前面的FF是微妙格式,和to_timestamp保持一致。

所以这条语句对123456789进行两次spell out。

先是123000000,保持百万位正确读取

然后是000456789,千位的读取。

ok

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10336955/viewspace-662957/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10336955/viewspace-662957/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值