ORACLE中date和timestamp的相互转化

时间:2021-04-29 21:27:19

oracle 中date类型精确可以年月日,时分秒,timestamp类型可以精确的秒一下

data转为timstamp

data 转为timstam可以函数to_timestamp的方式来转化:

SQL> Select to_timestamp('2006-01-01 12:10:10.1','yyyy-mm-dd hh24:mi:ss.ff') From dual; TO_TIMESTAMP('2006-01-0112:10:10.1','YYYY-MM-DDHH24:MI:SS.FF') ---------------------------------------------------------------------------
01-1月 -06 12.10.10.100000000 下午

timestamp转化为data
1, timestamp+0

SQL> select Systimestamp+0 FROM DUAL;

SYSTIMESTAMP+0 --------------
12-8月 -15

2, to_char的方式

SQL> Select to_char(Systimestamp,'yyyymmdd') From dual; TO_CHAR( --------
20150812

3,cast转化

SQL> Select Cast(Systimestamp As Date) From dual;

CAST(SYSTIMEST --------------
12-8月 -15