加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle SQL – DATE大于语句

发布时间:2020-12-12 13:48:54 所属栏目:百科 来源:网络整理
导读:正如标题所示,我想通过查询找到一种方法来检查我的数据集是从SYSDATE过去6个月. SELECT * FROM OrderArchiveWHERE OrderDate = '31 Dec 2014'; 我已经尝试了以下,但它返回一个错误,说我的日期格式是错误的.但是,插入数据我根据请求/打算使用该日期格式,没有
正如标题所示,我想通过查询找到一种方法来检查我的数据集是从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');

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读