I have a table that has a column named RANK
which is a keyword in Oracle.
Now I need to insert data in this table :
insert into mytbl (RANK)
select RANK from other_table
when executing this query I got the following error :
ORA-00907: missing right parenthesis
How does one escape a keyword?
Using Keywords in Tables or Columns Generally, SQL developers advise against using reserved words. However, if you want (or need) to use a reserved word as a table or column name, you can place the respective identifier in special quotation marks, so-called backticks (` `), in the SQL statements.
In SQL, certain words are reserved. These are called Keywords or Reserved Words. These words cannot be used as identifiers i.e. as column names in SQL.
Within SQL certain words are reserved. You cannot use an SQL reserved word as an SQL identifier (such as the name for a table, a column, an AS alias, or other entity), unless: The word is delimited with double quotes ("word"), and. Delimited identifiers are supported.
To escape reserved keywords in SQL SELECT statements and in queries on views, enclose them in double quotes ('').
Oracle uses double quotes "
to escape reserved words.
insert into mytbl ("RANK")
select "RANK"
from other_table
One other note, Oracle requires correct case as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With