Sometimes we use the same name as the oracle keyword when defining the field name and alias. What should we do now? This article will introduce in detail. For more information, see
Sometimes we use the same name as the oracle keyword when defining the field name and alias. What should we do now? This article will introduce in detail. For more information, see
What should we do when defining the field name and alias with the same name as the oracle keyword?
In fact, it is very easy to add "", such as "group" to this keyword"
See the following example:
The Code is as follows:
SQL> DROP TABLE k;
Table dropped
-- Create Table K with the field name UID (oracle keyword)
SQL> CREATE TABLE k (UID INT );
Create table k (uid int)
The ORA-00904: invalid IDENTIFIER
-- Field name and "" table created successfully
SQL> CREATE TABLE k ("UID" INT );
Table created
-- Insert some 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
-- "Not added" during query is normal (it does not seem to comply with the specifications)
SQL> SELECT UID FROM k;
UID
----------
5
5
5
SQL> SELECT "UID" FROM k;
UID
---------------------------------------
1
2
3
-- "" Must be added during update ""
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 reference keywords as field names and alias of query statements in the form of "keywords. It is recommended that you do not use it in special cases to avoid errors during code writing.