直接上方法。
1、timestamp –>Date
cast(systimestamp as date)也可以将timestamp转换成Date。
select cast(systimestamp as Date) from Dual;
systimestamp --26-4月 -17 07.14.45.466000 下午 +08:00
rusult --2017/4/26 19:14:01
(timestamp-0)可以直接将timestamp类型数据转换 成Date。
select systimestamp - 0 from Dual;
systimestamp --26-4月 -17 07.14.45.466000 下午 +08:00
rusult --2017/4/26 19:15:51
最后一种方式是用to_char,to_date,to_timestamp进行格式转换
select to_date(to_char(systimestamp,
'YYYYMMDD HH24:MI:SS'),
'YYYYMMDD HH24:MI:SS')
from dual;
systimestamp --26-4月 -17 07.16.47.676000 下午 +08:00
rusult --2017/4/26 19:17:58
2、Date–>timestamp
可以用to_char,to_date,to_timestamp进行转换。
select to_timestamp(to_char(to_date('20170101 12:12:12',
'YYYYMMDD HH24:MI:SS'),
'YYYYMMDD HH24:MI:SS'),
'YYYY-MM-DD HH24:MI:SS')
from dual;
Date --20170101 12:12:12
result --01-1月 -17 12.12.12.000000000 下午