如何转义 Oracle 中的保留字?

发布于 2024-07-27 17:14:01 字数 277 浏览 4 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

暮倦 2024-08-03 17:14:01

通过快速搜索,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.

他夏了夏天 2024-08-03 17:14:01

Oracle 通常需要双引号来分隔 SQL 语句中的标识符名称,例如,

SELECT "MyColumn" AS "MyColAlias"
FROM "MyTable" "Alias"
WHERE "ThisCol" = 'That Value';

但是,它慷慨地允许省略双引号,在这种情况下,它会悄悄地将标识符转换为大写:

SELECT MyColumn AS MyColAlias
FROM MyTable Alias
WHERE ThisCol = 'That Value';

在内部转换为类似以下内容:

SELECT "ALIAS" . "MYCOLUMN" AS "MYCOLALIAS"
FROM "THEUSER" . "MYTABLE" "ALIAS"
WHERE "ALIAS" . "THISCOL" = 'That Value';

Oracle normally requires double-quotes to delimit the name of identifiers in SQL statements, e.g.

SELECT "MyColumn" AS "MyColAlias"
FROM "MyTable" "Alias"
WHERE "ThisCol" = 'That Value';

However, it graciously allows omitting the double-quotes, in which case it quietly converts the identifier to uppercase:

SELECT MyColumn AS MyColAlias
FROM MyTable Alias
WHERE ThisCol = 'That Value';

gets internally converted to something like:

SELECT "ALIAS" . "MYCOLUMN" AS "MYCOLALIAS"
FROM "THEUSER" . "MYTABLE" "ALIAS"
WHERE "ALIAS" . "THISCOL" = 'That Value';
一影成城 2024-08-03 17:14:01

当我将关键字作为列名之一时,双引号在 Oracle 中起作用。

例如:

select t."size" from table t 

double quotes worked in oracle when I had the keyword as one of the column name.

eg:

select t."size" from table t 
¢好甜 2024-08-03 17:14:01

Oracle 确实使用双引号,但您很可能需要将对象名称置于大写,例如“TABLE”。 默认情况下,如果您创建一个不带双引号的对象,例如

CREATE TABLE table AS ...

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.

CREATE TABLE table AS ...

Oracle would create the object as upper case. However, the referencing is not case sensitive unless you use double-quotes!

属性 2024-08-03 17:14:01

您必须将该列重命名为其他名称,因为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文