oracle日期時間型timestamp相關學習

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.123456789', 'syyyy-mm-dd hh24:mi:ss.ff') from dual; 

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;  

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;
發佈了15 篇原創文章 · 獲贊 12 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章