[整理]oracle中几个特殊的函数

1、全角转半角函数 TO_SINGLE_BYTE
2、数字转英文,利用to_char、to_date
3、sys_guid()

[@more@]

1、全角转半角函数 TO_SINGLE_BYTE

SQL> select TO_SINGLE_BYTE('oracle') from dual;

TO_SINGLE_BYTE('ORACLE')
------------------------------
oracle

2、数字转英文,利用to_char、to_date

SQL> select to_char(to_date('12345','J'),'Jsp') en from dual;

en
----------------------------------------
Twelve Thousand Three Hundred Forty-Five

不过有限制:一是长度的限制,二是不能转换带小数的

SQL> select to_char(to_date('88888882345','J'),'Jsp') from dual;

select to_char(to_date('88888882345','J'),'Jsp') from dual

ORA-01854: julian 日期必须介于 1 和 5373484 之间

julian date指的是公元前4712年1月1日起经过的天数.

the inner TO_CHAR simply converts the number (which would probably be a numeric variable in practice) to CHAR so some magic can happen ...

the TO_DATE converts the CHAR using the J (Julian day) format. (the Julian day is the number of days since January 1, 4712BC, which is when SQL*Plus was invented),

having established the date value, we then convert that date back to a Julian day. Because the TO_CHAR in this case is used in DATE context, we can use the J mask to duplicate the original value, and append the SP (spell) format mask. 'Spell" does exactly that - it converts the number to words, hence the string value above.
SP can be used in a number of situations. For example, if SYSDATE is 26-AUG-98, then :

SELECT TO_CHAR ( SYSDATE, 'DdSp') FROM dual; -- spells the day as Twenty-Six,
and
SELECT TO_CHAR ( SYSDATE, 'DDSPTH') FROM dual; --returns TWENTY-SIXTH

3、sys_guid()

Oracle里有一个SYS_ID函数,可以产生GUID,但是返回的是32字节的字符串,但是如果用字符串作为主键的话效率不高

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

转载于:http://blog.itpub.net/594892/viewspace-966376/

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值