Oracle Field case Problem __oracle

Source: Internet
Author: User

When you create a table today, the fields are enclosed in quotes, and when you select the field you tell the field to find it, as shown in the following example:


Sql> CREATE TABLE Test ("id" varchar2);

Table created.

sql> desc test;
 Name                                      Null?    Type
 -----------------------------------------------------------------------------
 ID                                                 VARCHAR2 (10)

sql> INSERT INTO test values (' 1 ');

1 row created.

Sql> commit;

Commit complete.

Sql> select ID from test;
Select ID from Test
       *
ERROR in line 1:
ORA-00904: ' ID ': invalid identifier


sql> select ' id ' from TE St;

ID
----------
1

sql> select * from test;

ID
----------
1

sql> 


After repeated experiments, if you build a table without quotes in the field, no matter how the query will not appear above the problem, after proving that the case problem. Continue the experiment:


Sql> CREATE TABLE Test (ID varchar2 ());
Table created.

Sql> desc Test
 Name                                      Null?    Type
 -----------------------------------------------------------------------------
 ID                                                 VARCHAR2 (10)

sql> INSERT INTO test values (' 2 ');   
1 row created.

Sql> commit;
Commit complete.

Sql> select ID from test;
ID
----------
2

sql> select ID from test;
ID
----------
2

sql> select * from test;
ID
----------
2

sql> select "id" from test;
Select ' id ' from test
       *
ERROR at line 1:
ORA-00904: ' ID ': invalid identifier

sql> select ' id ' from Test;
ID
----------
2

sql> 


specifically as follows:

The id=id= "id" 1th ID is converted to an uppercase ID by default, and the second ID is converted to an uppercase ID by default, and the third is not converted and, because of the quotation mark, it is uppercase, so three equals.

(above line is not equal to line below)

The "id" = " ID" 1th "id" is quoted as a quotation mark and is lowercase, so reference to the field can only be referenced with an "id" and any other form will be an error.


Conclusion: Oracle fields, when not quoted, are all converted to uppercase by default.

When quoted, it is not automatically converted, what is written, what is, when the field is referenced, if the case does not match the error ORA-00904: "ID": Invalid identifier



Because of the above characteristics, 2 field names may appear as follows:


sql> drop table test;
Table dropped.

Sql> CREATE TABLE Test ("id" VARCHAR2 (), id varchar2 ());
Table created.

sql> desc test;
 Name                                      Null?    Type
 -----------------------------------------------------------------------------
 ID                                                 VARCHAR2 (10)
 ID                                                 VARCHAR2 (sql>)

insert INTO test values (' 3 ', ' 3 ');
1 row created.

Sql> select * from test;
ID         ID
--------------------
3          3



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.