1. 程式人生 > >ORA-01861: 文字與格式字串不匹配;literal does not match format string;

ORA-01861: 文字與格式字串不匹配;literal does not match format string;

問題描述: 儲存系統當前時間,精確到時分秒

錯誤sql

time date型別欄位
update t_table SET time = to_char(sysdate,'yyyy-MM-dd HH24:mi:ss')

報錯資訊: ORA-01861: 文字與格式字串不匹配
在這裡插入圖片描述

在這裡插入圖片描述


處理方式:

select sysdate from dual;
select to_date(sysdate) from dual;
select to_char(sysdate) from dual;

2018-12-15 16:07:35
2018-12-15 00:00:00
15-DEC-18

下面的寫法有區別:

update t_table SET time = to_date(to_char(sysdate),'yyyy-MM-dd HH24:mi:ss') 
update t_table SET time = to_date(to_date(sysdate),'yyyy-MM-dd HH24:mi:ss') 
update t_table SET time = to_date(sysdate,'yyyy-MM-dd HH24:mi:ss') 
update t_table SET time = to_date (
(select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual), 
'yyyy-mm-dd hh24:mi:ss')
update t_table SET time =(select sysdate from dual)

15-12-18 00:00:00
15-12-18 00:00:00
15-12-18 00:00:00
2018-12-15 16:07:35
2018-12-15 16:07:35