The oracle keyword is used as the field name

  • 2020-12-26 05:59:40
  • OfStack

Sometimes when we define field names and aliases with the same name as the oracle keyword, what do we do?
It's as simple as adding "" "to the key, as in "group"
Look at the following example:
 
SQL> DROP TABLE k; 
Table dropped 
--  Set up table K , field name UID ( oracle Keywords)  
SQL> CREATE TABLE k(UID INT); 
CREATE TABLE k(UID INT) 
ORA-00904: : invalid IDENTIFIER 
--  The field name to add "" Table created successfully  
SQL> CREATE TABLE k("UID" INT); 
Table created 
-- insert 1 Some of the data  
SQL> INSERT INTO k VALUES(1); 
1 row inserted 
SQL> INSERT INTO k VALUES(2); 
1 row inserted 
SQL> INSERT INTO k VALUES(3); 
1 row inserted 
--  Does the query add or not "" Normal (it doesn't seem to fit the norm)  
SQL> SELECT UID FROM k; 
UID 
---------- 
5 
5 
5 
SQL> SELECT "UID" FROM k; 
UID 
--------------------------------------- 
1 
2 
3 

-- update Must be added to "" 
SQL> UPDATE k SET UID=5 WHERE UID=3; 
UPDATE k SET UID=5 WHERE UID=3 
ORA-01747: invalid user.table.column, table.column, or column specification 
SQL> UPDATE k SET "UID"=5 WHERE "UID"=3; 

1 row UPDATED
Summary: oracle can refer to keywords in the form of "keywords" as aliases for field names and query statements. It is best not to use it unless it is a special case, in order not to cause errors in your code.

Related articles: