How to use oracle keywords as Field Names

Source: Internet
Author: User
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.

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.