Oracle to_date() to_timestamp() 毫秒

Oracle to_date() to_timestamp() 毫秒

转自http://hi.baidu.com/suofang/item/a78e3c394d41fb8af5e4ad10。

to_date如何取得毫秒?

由于oracle中date类型只支持到秒,不支持到毫秒,所以to_date()不能取到毫秒。如果要取到毫秒,oracle 9i以上版本,可以使用timestamp类型,是date的扩展类型,能支持到毫秒,毫秒的显示精度是6位,不过有效位是3位,即最大值达到999,满1000ms就进为1s。而与to_date()对应的转换函数可以使用to_timestamp()。select to_timestamp('2011-12-15 10:40:10.345', 'yyyy-MM-dd HH24:MI:ss.ff') as mydate from dual;如果想将timestamp又转换成date类型,可以使用cast()函数,但得到的date类型没有了毫秒值。如下:

select cast(to_timestamp('2011-12-15 10:40:10.345', 'yyyy-MM-dd HH24:MI:ss.ff') as date) as mydate from dual;

原文地址:https://www.cnblogs.com/handsome1013/p/9229588.html