How do I escape a reserved word in Oracle?

后端 未结 5 1266
野的像风
野的像风 2020-11-22 15:49

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?

5条回答
  •  长发绾君心
    2020-11-22 16:00

    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';
    

提交回复
热议问题