oracle时间怎么转字符串

oracle时间怎么转字符串

工作中编写过的一条语句

select * from Bt_Holiday whereto_char(Setting_DATE,'YYYY')=Substr('2015-03-00',1,4) AND to_char(Setting_DATE,'MM')=Substr('2015-03-00',6, (instr('2015-03-00','-',1,2))-(instr('2015-03-00','-',1)+1))
Substr('2015-03-00',6, (instr('2015-03-00','-',1,2))-(instr('2015-03-00','-',1)+1))

语句的意思是取得日期中的月。

to_char()函数功能,就是将数值型或者日期型转化为字符型

select to_char(sysdate,'YYYY') from dual         输出为:2015 select to_char(sysdate,'MM') from dual         输出为:08 select to_date('2001-12-01','yyyy-mm-dd') from dual 输出为:2001/12/01 select sysdate from dual      输出为:2015/8/17 20:14:34 Substr('原始字符串','第几个字符开始','截取几个字符')  select Substr('2015-03-00',1,4)  from dual   输出为:2015

Instr(‘源字符串string1′,’要在string1中查找的字符串string2′,’从第几个字符开始’,’要查找第几次出现字符串string2′)返回要截取的字符串在源字符串中的位置。

推荐教程: 《Oracle教程

以上就是

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享