oracle 日期和時間轉換


1、timestamp與字符串轉換

timestamp轉字符串:select to_char(t.timestamp,'yyyy-mm-dd HH24:mi:ss.ff') from tb_a t

 字符串轉timestamp:update tb_a t set t.timestamp=to_timestamp('2012-12-12 12:12:12.0','yyyy-mm-dd hh24:mi:ss.ff')  where t.id='1'

2、date與字符串轉換

select to_char(sysdate,'yy-mm-dd hh24:mi:ss') from dual   //顯示:08-11-07 13:22:42

select to_date('2005-12-25,13:25:59','yyyy-mm-dd hh24:mi:ss') from dual //顯示:2005-12-25 13:25:59

3、hh24:mi:ss.ff 

 

ff后面的數字表示 秒后面的小數位

 

--查詢當前系統日期:
Oracle: select to_char(sysdate, 'yyyy-mm-dd') from dual;
Mysql:select current_date();或者 select curdate();
--查詢當前系統時間:
Oracle: select to_char(sysdate, 'hh24:mi:ss') from dual;
Mysql: select curtime();或者 select current_time();
--查詢系統日期和時間:
Oracle: select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
Mysql: select sysdate(); 或者 select now();
--時間戳:
Oracle: select systimestamp from dual;
Mysql: select current_timestamp()

 

 4、oracle數據庫 TIMESTAMP(6)時間戳類型

--時間戳類型,參數6指的是表示秒的數字的小數點右邊可以存儲6位數字,最多9位。由於時間戳的精確度很高,我們也常常用來作為版本控制。插入時,如下方式:
insert into test4 values(to_timestamp('2019-7-19 23:23:23.112324233','yyyy-mm--dd hh24:mi:ss.ff'));

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM