新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > 数据库 > Oracle教程 > 正文:带你深入了解Oracle中几个相对特殊的函数

带你深入了解Oracle中几个相对特殊的函数

新客网 XKER.COM 2008-02-02 来源:赛迪网 陈劲 收藏本文

1、全角转半角函数 TO_SINGLE_BYTE

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

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

2、数肿⑽模胻o_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字节的字符串,但是假如用字符串作为主键的话效率将会不高。

收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐