正如标题所说,我想找到一种方法来通过查询检查我的哪些数据集是从 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/