oracle-查询优化改写-日期操作

日期类型: oracle中常用的类型有两个:DATE和TIMESTAMP. DATE精确到秒。 TIMESTAMP可以保存到秒的小数。

select current_date,current_timestamp from dual;

current_date                            current_timestamp
2020-12-07 11:30:30.             2020-12-07 11:30:30.089563
  1. date:类型相见的到的结果为整型,单位是天。

  2. timestamp:类型相减或timestamp与date相减的到的结果类型为interval。

  3. timestamp与数值加减后的到的是date类型,损失了精读,如果要保留精度可以改用时间间隔类型(interval)

  4. 月份加减不能使用interval类型:

~~

列举一些常用的oracle中的时间取值方式,希望对大家有用。

~~

select hiredate,
			to_number(to_char(hiredate,'hh24')) 时,
			to_number(to_char(hiredate,'mi')) 分,
			to_number(to_char(hiredate,'ss')) 秒,
			to_number(to_char(hiredate,'dd')) 日,
			to_number(to_char(hiredate,'mm')) 月,
			to_number(to_char(hiredate,'yyyy')) 年,
			to_number(to_char(hiredate,'ddd')) 年内第几天,
			trunc(hiredate,'dd') 一天之始,
			trunc(hiredate,'day') 周初,
			trunc(hiredate,'mm') 月初,
			last_day(hiredate) 月末,
			add_months(trunc(hiredate,'mm'),1) 下月初,
			trunc(hiredate,'yy') 年初,
			to_char(hiredate,'day') 周几,
			to_char(hiredate,'month') 月份
			from (select hiredate+30/24/60/60+20/24/60+5/24/ as hiredate from emp where rownum<=1)
			
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值