1. 程式人生 > 實用技巧 >SQL查詢錯誤_Oracle日期格式ORA-01841

SQL查詢錯誤_Oracle日期格式ORA-01841

1、Oracle日期格式ORA-01841: (full) year must be between -4713 and +9999, and not be 0

這種情況基本上就是要格式化的資料是錯的

select trunc(starttime)date1,sum(startmainqty) qty 
from rep_wafer_start_detail 
where starttime>=to_date('2020-10-10','yyyy-mm-dd')
and starttime<to_date('2020-10-20','yyyy-mm-dd')
and bg_id='ICBG' group
by trunc(starttime) -------------錯誤日期更換-------------------- select trunc(starttime)date1,sum(startmainqty) qty from rep_wafer_start_detail where starttime>=to_date('&v_start&','yyyy-mm-dd') and starttime<to_date('&v_end&','yyyy-mm-dd') and bg_id='ICBG' group by trunc(starttime)
--------------正確日期更換(VB)---------------- where starttime>=to_date('"&v_start&"','yyyy-mm-dd') and starttime<to_date('"&v_end&"','yyyy-mm-dd')

不是日期格式的資料,原因:

在進行SQL查詢時首先以固定時間帶入,再在引用程式中更換為變數,更換過程變數格式錯誤導致日期格式錯誤