在oracle中比较两次
在 Oracle 中:
我的表有一个时间戳列,时间值为“02-NOV-11 12.00.00.000000000 AM”。
我尝试比较两个日期:
select id from table1 where mytime = '02-NOV-11'
但它没有返回任何记录。为什么?
谢谢!!!
In Oracle :
My table has a timestamp column with time value of '02-NOV-11 12.00.00.000000000 AM' .
I tried to compare two dates:
select id from table1 where mytime = '02-NOV-11'
But it returns no records. Why?
Thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑这可能是导致问题的默认日期格式,因为查询对我来说工作正常。编写将日期与字符串进行比较的查询并不是一个好习惯,因为这需要 Oracle 使用默认格式将字符串格式化为日期,而这可能与您期望的不同。最好使用这样的 ANSI 日期文字:
ANSI 日期文字必须采用
date 'yyyy-mm-dd'
格式,因此格式不会有歧义。日期时间文字的参考
I suspect it may be the default date format that is causing the problem, since the query works fine for me. It is not good practice to write queries that compare dates with strings, since this requires Oracle to format the string into a date using the default format, which may not be as you expect. It is better to use ANSI date literals like this:
ANSI date literals must be in the format
date 'yyyy-mm-dd'
, so there is no ambiguity about format.A reference for datetime literals