Oracle比较两个不同的日期 [英] Oracle compare two different dates
问题描述
以下查询无法从java执行.在这里我使用oracle xe服务器
The following query cant execute from java . Here i use oracle xe server
datetrx <= to_date('2014-07-16 00:00:00.0','yyyy/mm/dd hh24:mi:ss.f')
datetrx
的日期格式为dd/mm/yyyy
datetrx
is in the date format of dd/mm/yyyy
推荐答案
您在to_date()
函数中输入的字符串与您的模式不匹配.该值包含-
作为分隔符,但是在模式中,您使用/
:
Your input string in the to_date()
function does not match your pattern. The value contains -
as the delimiter, however in the pattern you use /
:
如果您将输入格式和图案对齐,这应该可以:
If you align your input format and the pattern, this should work:
datetrx <= to_date('2014-07-16 00:00:00','yyyy-mm-dd hh24:mi:ss')
我个人更喜欢ANSI时间戳文字而不是to_date()
函数,因为它们是可移植的并且键入更少:
I personally prefer ANSI timestamp literals over the to_date()
function because they are portable and it's less typing:
datetrx <= timestamp '2014-07-16 00:00:00'
请注意,此处提供的字符串的格式始终是 ISO格式.
Note the format the string supplied here is always the ISO format.
旁注:
查看列daterx
中的值时看到的任何格式"均由用于显示该数据的SQL客户端(SQL * Plus,SQL Developer等)应用.
A side note:
Any "format" you see when looking at the values in the column daterx
is applied by the SQL client you use to display that data (SQL*Plus, SQL Developer, ...).
值本身以格式存储在服务器上. DATE
值的格式始终由SQL客户端(或您的应用程序)完成 :
The value itself is stored without a format on the server. Formatting of a DATE
value is always done by the SQL client (or your application):
这篇关于Oracle比较两个不同的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!