How do I escape a reserved word in Oracle?

后端 未结 5 1220
野的像风
野的像风 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';
    
    0 讨论(0)
  • 2020-11-22 16:00

    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.

    0 讨论(0)
  • 2020-11-22 16:09

    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.

    0 讨论(0)
  • 2020-11-22 16:14

    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!

    0 讨论(0)
  • 2020-11-22 16:16

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

    eg:

    select t."size" from table t 
    
    0 讨论(0)
提交回复
热议问题