ORA-01830: 日期格式图片在转换整个输入字符串之前结束 - JAVA / Oracle

我正在使用以下查询将我的日期输入字符串MM-dd-YYYY格式转换为格式:SQL timestamp


DateFormat format = new SimpleDateFormat("MM-dd-YYYY", Locale.ENGLISH);

java.util.Date endDate = format.parse(myEndDateString);

endDateTimestamp = Calendar.getInstance();

endDateTimestamp.setTime(endDate);

endDateTimestamp.set(Calendar.MILLISECOND, 0);

时间戳现在已按预期格式更新。


30-DEC-18 12.00.00.000000000 AM

我的数据库中有几行像这样更新。现在,当我希望将来使用以下方法获取日期时:


select * from my_records where end_dt > sysdate;

我得到一个例外:


ORA-01830: 日期格式图片在转换整个输入字符串之前结束。


有没有其他方法可以将字符串更新为时间戳,或者是否应该修改查询?


更新:我的表列end_dt在TIMESTAMP类型中。


喵喵时光机
浏览 232回答 1
1回答

HUX布斯

如果END_DT列的数据类型是DATE,那么您的查询将起作用。看来不是,而是VARCHAR2。如果是这样,您必须TO_DATE使用适当的格式掩码对其应用功能才能使其正常工作。例如:select * From my_recordswhere to_date(substr(end_dt, 1, 9), 'dd-mon-yy') > sysdate30-DEC-18 12.00.00.000000000 AM---------this makes SUBSTR(end_dt, 1, 9), and its format mask is dd-mon-yy[编辑]你说它的数据类型是时间戳。如果是,那么您的查询将起作用。看看这个例子:SQL> create table test (end_dt timestamp);Table created.SQL> insert into test values (systimestamp);1 row created.SQL> select * From test where end_dt < sysdate;END_DT----------------------------------------------------02.02.19 20:42:08,375000SQL>你能验证它真的是TIMESTAMP(不是看起来像,而是真的是)。通过运行 DESC 命令来做到这一点:SQL> desc test&nbsp;Name&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Null?&nbsp; &nbsp; Type&nbsp;----------------------------------------- -------- ---------------&nbsp;END_DT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TIMESTAMP(6)SQL>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java