oracle sql日期操作

1、转换函数
      与date操作关系最大的就是两个转换函数:to_date(),to_char()
      to_date() 作用将字符类型按一定格式转化为日期类型:
      具体用法:to_date(''2004-11-27'',''yyyy-mm-dd''),前者为字符串,后者为转换日期格式,注意,前后两者要以一对应。
      如;to_date(''2004-11-27 13:34:43'', ''yyyy-mm-dd hh24:mi:ss'') 将得到具体的时间

      多种日期格式:

      YYYY:四位表示的年份
      YYY,YY,Y:年份的最后三位、两位或一位,缺省为当前世纪
      MM:01~12的月份编号
      MONTH:九个字符表示的月份,右边用空格填补
      MON:三位字符的月份缩写
      WW:一年中的星期
      D:星期中的第几天
      DD:月份中的第几天
      DDD:年所中的第几天
      DAY:九个字符表示的天的全称,右边用空格补齐
      HH,HH12:一天中的第几个小时,12进制表示法
      HH24:一天中的第几个小时,取值为00~23
      MI:一小时中的分钟
      SS:一分钟中的秒
      SSSS:从午夜开始过去的秒数

      to_char():将日期转按一定格式换成字符类型

----------------------------------------------------------
delete from (select *
    from mst_sms_status t
   where phone > 18999999999
     and phone like '%189_%'
     and t.create_date >
         to_date('2013-08-12 00:00:00', 'yyyy-mm-dd hh24:mi:ss'))

oracle sql日期比较:
在今天之前:
select * from up_date where update < to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from up_date where update <= to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

在今天只后:
select * from up_date where update > to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from up_date where update >= to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

精确时间:
select * from up_date where update = to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

在某段时间内:
select * from up_date where update between to_date('2007-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from up_date where update < to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and update > to_date('2007-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from up_date where update <= to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and update >= to_date('2007-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

猜你喜欢

转载自ych0108.iteye.com/blog/1923654