LESS THAN OR EQUAL TO IN Oracle SQL(小于或等于 Oracle SQL)
问题描述
updated_date = 08-Jun-2010;
我有一个这样的查询
select * from asd whre updated_date <= todate('08-Jun-2010', 'dd-MM-yy');
但我没有得到任何结果.它仅适用于 todate 是 09-Jun-2010...
but I am not getting any results. it only works if todate is 09-Jun-2010...
即我的 equalto 操作符工作不正常.
i.e. my equalto operator is not working properly.
为什么会这样?
推荐答案
在 Oracle 中,DATE 是一个时间点.它总是有一个精确到秒的时间分量.todate('08-Jun-2010', 'dd-Mon-yyyy') 在 Oracle 中与 todate('08-Jun-2010 00:00:00', 'dd-Mon-yyyy hh24:mi:ss').因此,如果您选择截至该日期的行,您将不会在当天获得任何时间分量不等于 00:00 的行.
In Oracle a DATE is a point in time. It always has a time component with a precision to the second. todate('08-Jun-2010', 'dd-Mon-yyyy') is in Oracle the same as todate('08-Jun-2010 00:00:00', 'dd-Mon-yyyy hh24:mi:ss'). So if you select rows up to that date you won't get any row on that day with a time component not equal to 00:00.
如果您想选择直到并包括 08-JUN-2010 的所有行,我建议使用:
If you want to select all the rows up to and including 08-JUN-2010, I would suggest using:
< to_date('09-06-2010', 'dd-MM-yyyy')
或
<= to_date('08-06-2010 23:59:59', 'dd-MM-yyyy hh24:mi:ss')
注意 - 我更正了您的日期格式:如果您想使用缩写的月份名称,则需要使用 MON.我建议改用 MM,这样当有人更改其客户端设置 (NLS_DATE_LANGUAGE) 时,您就不会出错.也更喜欢使用 YYYY 而不是 YY.
Note - I corrected your date format: you need to use MON if you want to use the abbreviated month name. I would suggest using MM instead, so that you won't get error when someone changes its client settings (NLS_DATE_LANGUAGE). Also prefer the use of YYYY instead of YY.
这篇关于小于或等于 Oracle SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:小于或等于 Oracle SQL
基础教程推荐
- 无法解决整理冲突 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
