从oracle sql中的timestamp中删除毫秒

时间:2014-05-02 06:20:44

标签: sql oracle plsql

我想从21-02-14 10:41:08.000000000 PM删除毫秒。

我试试

select to_date('21-02-14 10:41:08.000000000 PM','DD/MM/YY HH:MI:SS:SSSSS PM') from dual;

错误

Error starting at line : 1 in command -
select to_date('21-02-14 10:41:08.000000000 PM','DD/MM/YY HH:MI:SS:PM') from dual
Error report -
SQL Error: ORA-01855: AM/A.M. or PM/P.M. required
01855. 00000 -  "AM/A.M. or PM/P.M. required"
*Cause:    
*Action:

1 个答案:

答案 0 :(得分:2)

您指定了小数秒,但您的格式在午夜过后了#34;" - 没有9位数字。当数据有点时,您还在格式字符串中指定冒号。尝试:

select cast(to_timestamp('21-02-14 10:41:08.000000000 PM','DD-MM-YY HH:MI:SS.FF9 PM') as date) from dual;