最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

oracle日期时间型timestamp相关转换

来源:动视网 责编:小采 时间:2020-11-09 15:15:18
文档

oracle日期时间型timestamp相关转换

oracle日期时间型timestamp相关转换:1、获取系统时间的语句(ssxff6获取小数点后面六位)select sysdate,systimestamp,to_char(systimestamp, 'yyyymmdd hh24:mi:ssxff6'), to_char(systimestamp, 'yyyymmdd hh24:mi:ss.ff6')
推荐度:
导读oracle日期时间型timestamp相关转换:1、获取系统时间的语句(ssxff6获取小数点后面六位)select sysdate,systimestamp,to_char(systimestamp, 'yyyymmdd hh24:mi:ssxff6'), to_char(systimestamp, 'yyyymmdd hh24:mi:ss.ff6')


1、获取系统时间的语句(ssxff6获取小数点后面六位)
select sysdate,systimestamp,to_char(systimestamp, 'yyyymmdd hh24:mi:ssxff6'),
to_char(systimestamp, 'yyyymmdd hh24:mi:ss.ff6') from dual;

2、字符型转成timestamp
select to_timestamp('2011-09-14 12:52:42.1234567', 'syyyy-mm-dd hh24:mi:ss.ff') from dual;

3、timestamp转成date型
select cast(to_timestamp('2011-09-14 12:52:42.1234567', 'syyyy-mm-dd hh24:mi:ss.ff') as date) timestamp_to_date from dual;

4、date型转成timestamp
select cast(sysdate as timestamp) date_to_timestamp from dual;

5、两date的日期相减得出的是天数,而两timestamp的日期相减得出的是完整的年月日时分秒小数秒
select sysdate-sysdate,systimestamp-systimestamp from dual;

select extract(day from inter) * 24 * 60 * 60 +
extract(hour from inter) * 60 * 60 + extract(minute from inter) * 60 +
extract(second from inter) "seconds" from
(
select to_timestamp('2011-09-14 12:34:23.281000000', 'yyyy-mm-dd hh24:mi:ss.ff') -
to_timestamp('2011-09-14 12:34:22.984000000', 'yyyy-mm-dd hh24:mi:ss.ff') inter from dual
);

select extract(second from to_timestamp('2011-09-14 12:34:23.281000000', 'yyyy-mm-dd hh24:mi:ss.ff'))-
extract(second from to_timestamp('2011-09-14 12:34:22.984000000', 'yyyy-mm-dd hh24:mi:ss.ff')) from dual;

注:所以,timestamp要算出两日期间隔了多少秒,要用函数转换一下。
to_char函数支持date和timestamp,但是trunc却不支持TIMESTAMP数据类型。

更多相关教程请访问 MySQL视频教程

文档

oracle日期时间型timestamp相关转换

oracle日期时间型timestamp相关转换:1、获取系统时间的语句(ssxff6获取小数点后面六位)select sysdate,systimestamp,to_char(systimestamp, 'yyyymmdd hh24:mi:ssxff6'), to_char(systimestamp, 'yyyymmdd hh24:mi:ss.ff6')
推荐度:
标签: 转换 时间 日期
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top