在oracle中比较两次

发布于 2024-12-13 01:30:46 字数 216 浏览 5 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请远离我 2024-12-20 01:30:46

我怀疑这可能是导致问题的默认日期格式,因为查询对我来说工作正常。编写将日期与字符串进行比较的查询并不是一个好习惯,因为这需要 Oracle 使用默认格式将字符串格式化为日期,而这可能与您期望的不同。最好使用这样的 ANSI 日期文字:

select id from table1 where mytime = date '2011-11-02';

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:

select id from table1 where mytime = date '2011-11-02';

ANSI date literals must be in the format date 'yyyy-mm-dd', so there is no ambiguity about format.

A reference for datetime literals

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文