SQL ORA-00920: 无效的关系运算符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24961804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 02:18:21  来源:igfitidea点击:

ORA-00920: invalid relational operator

sqloracle

提问by Ryan_W4588

In a database, I am trying to pull information that is later than a specified date. I should note beforehand that the date is in an odd format: YYYYMMDDHH24MISS##where ##is a two letter string which defines something useless to my query. Thus, I am using substrto just remove them.

在数据库中,我试图提取晚于指定日期的信息。我应该事先注意日期的格式很奇怪:YYYYMMDDHH24MISS##where##是一个两个字母的字符串,它定义了对我的查询无用的东西。因此,我substr只是用来删除它们。

My query, below, throws the following error, and I canot find out why:

我的查询,下面,抛出以下错误,我无法找出原因:

[Error Code: 920, SQL State: 42000] ORA-00920: invalid relational operator

[错误代码:920,SQL 状态:42000] ORA-00920:关系运算符无效

My Query:

我的查询:

SELECT *
  FROM table_name
 WHERE to_date(substr(COLUMN_NAME,1,14), 'YYYYMMDDHH24MISS')) >=
       to_date('MIN_DATE', 'YYYYMMDDHH24MISS')

I have checked to make sure the dates are being defined correctly, and they are.

我已经检查过以确保正确定义了日期,并且确实如此。

Example of what I have used for MIN_DATEis: 20140101000000

我使用的示例MIN_DATE是:20140101000000

回答by John Maillet

You have an extra parenthesis at the end of the first to_date

在第一个 to_date 的末尾有一个额外的括号

回答by Gordon Linoff

You get this error in Oracle when you are missing a comparison operation, such as =-- as John Maillet already noted.

当您缺少比较操作时,您会在 Oracle 中收到此错误,例如=-- 正如 John Maillet 已经指出的那样。

My concern is the second part of the whereclause:

我担心的是该where条款的第二部分:

where to_date(substr(COLUMN_NAME, 1, 14), 'YYYYMMDDHH24MISS') >=
                  to_date('MIN_DATE', 'YYYYMMDDHH24MISS')

You have MIN_DATEin single quotes. This is interpreted as a stringwith eight letters in it, starting with 'M'and ending with 'E'. This is not interpretedas a variable. Presumably you mean:

你有MIN_DATE单引号。这被解释为一个包含八个字母的字符串'M''E'. 这不被解释为变量。想必你的意思是:

where to_date(substr(COLUMN_NAME, 1, 14), 'YYYYMMDDHH24MISS') >=
                  to_date(MIN_DATE, 'YYYYMMDDHH24MISS')

You should only use single quotes for string and date constants.

您应该只对字符串和日期常量使用单引号。

I should add that you should be able to do this comparison without having to convert to dates:

我应该补充一点,您应该能够进行此比较而无需转换为日期:

where left(COLUMN_NAME, 14) = MIN_DATE