Oracle 日期函数
我正在执行以下查询,它返回空白行。但是表中有 upd_time = '12-MAR-08' 的记录。我不明白为什么它不返回日期 '12-MAR-08 '.请帮帮我?
从 BANKREC.br_data 中选择 br_data.upd_time 其中 br_data.upd_time = '12-MAR-08';
I am executing the below query,It returns me the blank row.However there are records in the table having upd_time = '12-MAR-08'.I don't understand why it is not returning the date '12-MAR-08'.Please help me out??
SELECT br_data.upd_time FROM BANKREC.br_data
where br_data.upd_time = '12-MAR-08';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
upd_time 可能不完全是 2008 年 3 月 12 日。日期格式没有显示时间部分,但它可能存在(Oracle 中的 DATE 数据类型可以同时包含日期和时间部分)。
试试这个(它可以让你看到时间成分):
It's likely that upd_time isn't exactly 12-MAR-08. The date format is not showing the time component, but it's probably there (DATE data type in Oracle can contain both date and time components).
Try this (it will allow you to see the time components):
如果您执行 a ,是否相同?
可能是 upd_time 不是日期,而是时间戳,因此它实际上包含例如“12-MAR-08 05:30”,这不是同一件事。
trunc()
删除时间戳的时间部分。由于它不会返回错误,我假设它正确解析了日期,但否则您可以尝试使用
to_date('12-MAR-08','DD-MON-YY')
Is it the same if you do a
It could be that the upd_time is not a date, but a timestamp, so it actually contains for instance '12-MAR-08 05:30' which wouldn't be the same thing.
trunc()
removes the time part of the timestamp.Since it doesn't return an error, I assume that it parses the date correctly, but otherwise you could try with
to_date('12-MAR-08','DD-MON-YY')
您应该使用 Oracle 的函数将字符串正确转换为日期,
然后您必须考虑到 Oracle“日期”数据类型还包含精确到秒的时间信息。这意味着第一步构建的日期实际上是 3 月 12 日午夜。因此,您必须确保 upd_time 被截断为午夜:
您的完整查询变成
There are other way to Skin this cat (您可以使用
to_char(upd_time, 'DD-MMM) 将 updTime 列转移到正确的 char 字段-YY')
),但通常建议您查找的数据与数据库中可以找到的数据相似,因为这会增加使用索引进行查找的机会。You should use Oracle's function to convert your string properly into a date using
Then you have to take into account that the Oracle "Date" datatype also contains time information to the nearest second. This means that the date that was constructed in the first step is actually midnight on March 12th. So you have to make sure that the upd_time is truncated to midnight:
Your full query becomes
There are other ways to skin this cat (you could transfer your updTime column to a proper char field with
to_char(upd_time, 'DD-MMM-YY')
), but it's usually advisable make the data you are looking for similar to what you can find in the database as that increases your chances of using an index for the lookup.我目前无法访问 oracle 数据库,但我记得使用 to_char。
尝试
i don't have access to an oracle db at the moment but i remember using to_char.
try