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

SQL Invalid identifier - only occurs when query is ran in script

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

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 语句?

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

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