sql - Oracle SQL - DATE 大于语句

标签 sql oracle date format

正如标题所说,我想找到一种方法来通过查询检查我的哪些数据集是从 SYSDATE 过去 6 个月的。

SELECT * FROM OrderArchive
WHERE OrderDate <= '31 Dec 2014';

我已尝试以下操作,但它返回一个错误,指出我的日期格式错误。但是,插入数据时我按照要求/预期使用了该日期格式,并且没有任何问题。

Error at Command Line : 10 Column : 25

Blockquote

Error report -

SQL Error: ORA-01861: literal does not match format string 01861. 00000 - "literal does not match format string"

*Cause: Literals in the input must be the same length as literals in the format string (with the exception of leading whitespace). If the "FX" modifier has been toggled on, the literal must match exactly, with no extra whitespace.

*Action: Correct the format string to match the literal.

最佳答案

由于您的查询字符串是文字,并且假设您的日期正确存储为 DATE 您应该使用 date literals :

SELECT * FROM OrderArchive
WHERE OrderDate <= DATE '2015-12-31'

如果您想使用TO_DATE (因为,例如,您的查询值不是文字),我建议您显式设置 NLS_DATE_LANGUAGE参数,因为您使用美国缩写月份名称。这样,它就不会在某些本地化的 Oracle 安装中中断:

SELECT * FROM OrderArchive
WHERE OrderDate <= to_date('31 Dec 2014', 'DD MON YYYY',
                           'NLS_DATE_LANGUAGE = American');

关于sql - Oracle SQL - DATE 大于语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30555790/

相关文章:

java - 将 weblogic JMS 移动到 Oracle 高级队列时出错

oracle - ORA-12505,TNS :listener does not currently know of SID given in connect

javascript - Ext js 使用另一个日期选择器的值处理设置日期选择器的 minDate

java - 月份字段的值 0 无效。将 util.date 转换为 XMLgregoriandate 时?

php - WordPress:如何使用 PHP 和 MySQL 更新数据库中的数据?

sql游标只返回一个值

java - 是否可以从Java代码调用数据库触发器?

mysql - 选择具有双重限制的 MySQL

oracle - 如何在 Oracle 中查找当前打开的游标

r - 使用两个数据框列应用 seq.Date