转换函数

1.  to_char(date,str)把指定日期转换为字符,还可以截取到想要的内容,如单独的年,月,日

select to_char(sysdate,'yyyy')from dual---2011

select to_char(sysdate,'fmyyyy-mm-dd')from dual-- 2011-6-9 fm取消月日前面的0

select to_char(sal,'L999,999,999') from emp--  $8,000 把数字换成美元

 

2.  to_number(arg)arg转换为数字类型

select to_number('13')+to_number('14') from dual—27

 

3.  to_date(arg1,arg2)把字符转化为日期

select to_date('20110206','yyyy-MM-dd') from dual;

 

4.  nvl(exp1,exp2)返回非空exp

select nvl(comm,0) from emp

 

5.  nullif(exp1,exp2)如果exp1=exp2,那么返回null,如果不相等,返回exp1

select nullif('aaa','aaa') from dual---null

 

6.  nvl2(exp1,exp2,exp3)---如果exp1为空,返回3,如果exp1不为空,返回exp2

select nvl2('','bbb','ccc') from dual---ccc

 

7.  coalesce(Nexp)返回第一个非null,可以是Nexp

select coalesce('','','cc') from dual---cc

 

8.  case exp1 when value1 then else end;实现多路分支结构

select empno,ename,sal,

case deptno

when 10 then '财务部'

when 20 then '研发部'

when 30 then '销售部'

else

'unkown'

end

from emp;

 

9.  decode(exp,value1,str1,value2,str2,str3)也是实现多路分支结构

select empno,ename,sal,

decode(deptno,10,'aaa',20,'bbb','未知部门') from emp

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

转载于:http://blog.itpub.net/25676270/viewspace-697595/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值