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