SQL无效标识符 - 仅在脚本中运行查询时发生

时间:2016-02-19 01:38:57

标签: sql oracle oracle-sqldeveloper

我在SQL Developer for Oracle数据库中编码,我有一个简单的查询如下:

select distinct location from Conference where name like '%SIGMOD%' and year >= 2003 and year <= 2008; 

当我自己运行查询时,我得到了预期的正确结果。但是当我把它作为脚本的一部分运行时,我得到了这个错误:

Error starting at line : 1 in command -
select distinct location from Conference where name like ‘%SIGMOD%’ and year >= 2003 and year <= 2008
Error at Command Line : 1 Column : 58
Error report -
SQL Error: ORA-00911: invalid character
00911. 00000 -  "invalid character"
*Cause:    identifiers may not start with any ASCII character other than
           letters and numbers.  $#_ are also allowed after the first
           character.  Identifiers enclosed by doublequotes may contain
           any character other than a doublequote.  Alternative quotes
           (q'#...#') cannot use spaces, tabs, or carriage returns as
           delimiters.  For all other contexts, consult the SQL Language
           Reference Manual.

我不确定发生了什么。

修改: 即使我将查询的部分更改为where name = 'SIGMOD',我仍然会收到相同的错误。

编辑2 : 傻傻的,我错误地运行了那个查询。 where name = 'SIGMOD'确实摆脱了错误。但是,我想知道为什么我不能在原始问题中使用like语句?

1 个答案:

答案 0 :(得分:1)

您需要将撇号更新为单引号。改变这个:

select distinct location 
from Conference 
where name like ‘%SIGMOD%’ and year >= 2003 and year <= 2008

为:

select distinct location 
from Conference 
where name like '%SIGMOD%' and year >= 2003 and year <= 2008