Oracle keywords as field names using method _oracle

Source: Internet
Author: User
What happens when we define a field name and alias with the same name as the Oracle keyword?
It's really simple, just add "" to this keyword, such as "group"
Look at the following example:
Copy Code code as follows:

sql> DROP TABLE k;
Table dropped
--establishes table K, field name UID (Oracle keyword)
sql> create TABLE K (UID INT);
CREATE TABLE K (UID INT)
ORA-00904:: Invalid IDENTIFIER
--field name plus "Table creation succeeded
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
--the query does not add "" is normal (does not seem to conform to the specification)
Sql> SELECT UID from K;
UID
----------
5
5
5
sql> Select "UID" from K;
UID
---------------------------------------
1
2
3

--Update must add ""
sql> U Pdate 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 as aliases for field names and query statements in the form of "keywords". It is best not to use it if it is not a special case, lest it cause errors in the code writing process.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.