oracle里面的时间转字符串to_char(),字符串转时间to_date(),以及substr和instr的使用。

时间:2023-03-09 20:14:39
oracle里面的时间转字符串to_char(),字符串转时间to_date(),以及substr和instr的使用。

工作中编写过的一条语句

select * from Bt_Holiday where
to_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')返回要截取的字符串在源字符串中的位置