Oracle SQL – DATE大于语句

前端之家收集整理的这篇文章主要介绍了Oracle SQL – DATE大于语句前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
正如标题所示,我想通过查询找到一种方法来检查我的数据集是从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@H_502_13@ 01861. 00000 – “literal does not match format string”

*Cause: Literals in the input must be the same length as literals in@H_502_13@ the format string (with the exception of leading whitespace). If the@H_502_13@ “FX” modifier has been toggled on,the literal must match exactly,@H_502_13@ 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');

猜你在找的Oracle相关文章