码迷,mamicode.com
首页 > 数据库 > 详细

PLSQL_基础系列9_时间戳Timestamp

时间:2014-12-12 14:33:57      阅读:376      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   strong   on   

2013-11-09 BaoXinjian

bubuko.com,布布扣1. 获取系统时间的语句(ssxff6获取小数点后面六位)

select sysdate,systimestamp,to_char(systimestamp, yyyymmdd hh24:mi:ssxff6),  to_char(systimestamp, yyyymmdd hh24:mi:ss.ff6) from dual; 

 

bubuko.com,布布扣2. 字符型转成timestamp

select to_timestamp(2011-09-14 12:52:42.123456789, syyyy-mm-dd hh24:mi:ss.ff) from dual;

 

bubuko.com,布布扣3. timestamp转成date型

select cast(to_timestamp(2011-09-14 12:52:42.123456789, syyyy-mm-dd hh24:mi:ss.ff) as date) timestamp_to_date from dual;

 

bubuko.com,布布扣4. date型转成timestamp

select cast(sysdate as timestamp) date_to_timestamp from dual;

 

bubuko.com,布布扣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 数据类型。

 

bubuko.com,布布扣

PLSQL_基础系列9_时间戳Timestamp

标签:style   blog   io   ar   color   os   sp   strong   on   

原文地址:http://www.cnblogs.com/eastsea/p/4154272.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!