如何转义 Oracle 中的保留字?
在 TSQL 中,我可以使用类似 Select [table] from tablename
的内容来选择名为“table”的列。
如何对 oracle 中的保留字执行此操作?
编辑:我尝试过方括号、双引号、单引号和反引号,它们不起作用...
作为进一步的说明,我有一个列,有人将其命名为评论。 由于这是一个保留字,oracle 正在尝试使用它进行选择,因此在解析查询时会失败。 我尝试过从表名中选择“评论”,但它不起作用。 我会检查一下情况然后回来。
In TSQL I could use something like Select [table] from tablename
to select a column named "table".
How do I do this for reserved words in oracle?
Edit: I've tried square braces, double quotes, single quotes, and backquotes, they don't work...
As a further clarification, I have a column which someone named comment. As this is a reserved word oracle is chucking a wobbly trying to select with it, it's failing when parsing the query. I've tried Select "comment" from tablename but it didn't work. I'll check case and come back.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通过快速搜索,Oracle 似乎使用双引号(
"
,例如"table"
)并且显然需要正确的大小写,而对于任何感兴趣的人,MySQL 默认使用反引号 (`),除非设置为使用双引号以实现兼容性。From a quick search, Oracle appears to use double quotes (
"
, eg"table"
) and apparently requires the correct case—whereas, for anyone interested, MySQL defaults to using backticks (`) except when set to use double quotes for compatibility.Oracle 通常需要双引号来分隔 SQL 语句中的标识符名称,例如,
但是,它慷慨地允许省略双引号,在这种情况下,它会悄悄地将标识符转换为大写:
在内部转换为类似以下内容:
Oracle normally requires double-quotes to delimit the name of identifiers in SQL statements, e.g.
However, it graciously allows omitting the double-quotes, in which case it quietly converts the identifier to uppercase:
gets internally converted to something like:
当我将关键字作为列名之一时,双引号在 Oracle 中起作用。
例如:
double quotes worked in oracle when I had the keyword as one of the column name.
eg:
Oracle 确实使用双引号,但您很可能需要将对象名称置于大写,例如“TABLE”。 默认情况下,如果您创建一个不带双引号的对象,例如
Oracle 将创建该对象为大写。 但是,除非使用双引号,否则引用不区分大小写!
Oracle does use double-quotes, but you most likely need to place the object name in upper case, e.g. "TABLE". By default, if you create an object without double quotes, e.g.
Oracle would create the object as upper case. However, the referencing is not case sensitive unless you use double-quotes!
您必须将该列重命名为其他名称,因为
TABLE
是由 Oracle 保留的。在oracle视图
V$RESERVED_WORDS
中可以看到Oracle的所有保留字。you have to rename the column to an other name because
TABLE
is reserved by Oracle.You can see all reserved words of Oracle in the oracle view
V$RESERVED_WORDS
.