一、獲取系統時間的語句(ssxff6獲取小數點後面六位)
select sysdate,systimestamp,to_char(systimestamp, 'yyyymmdd hh24:mi:ssxff6'),
to_char(systimestamp, 'yyyymmdd hh24:mi:ss.ff6') from dual;
二、字符型轉成timestamp
select to_timestamp('2011-09-14 12:52:42.123456789', 'syyyy-mm-dd hh24:mi:ss.ff') from dual;
三、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;
四、date型轉成timestamp
select cast(sysdate as timestamp) date_to_timestamp from dual;
五、兩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數據類型。 ide
轉至:http://hulu26.iteye.com/blog/1171749函數