‘ORA-00904: "AGE": invalid identifier’ The association between double quote and case sensitivity

来源:互联网 发布:演唱会软件推荐 编辑:程序博客网 时间:2024/05/16 17:39

异常原因

造成‘ORA-00904: "AGE": invalid identifier’ 的根本原因是数据库不能识别你所给出的列。可能是列名写错了,大小写敏感。以下主要讲解如何解决由大小写敏感造成的这个问题。

A solution from Stack overflow:

Oracle SQL allows us to ignore the case of database object names provided we either create them with names all in upper case, or without using double quotes. If we use mixed case or lower case in the script and wrapped the identifiers in double quotes we are condemned to using double quotes and the precise case whenever we refer to the object or its attributes.

大意阐述:

1.当我们使用全大写加引号或者不在列上使用双引号时创建表的时候,数据库是大小写不敏感的。

全大写加引号:

 create table allupper(   "NAME" varchar2(8),   "AGE" number);

select name,AGE from allupper;

结果:查询可通过。


不在列上使用双引号:

 create table noquote(   name varchar2(8),   age number);

 select name,AGE from noquote;

结果:查询可通过。

2.如果使用了“”而且列名包含大小写, 那么你必须使用和创建表时一模一样的列名,并且加上“”。

使用了双引号,并且还有大小写

create table mixcase(  "NAme" varchar2(8),   "Age" number);

 select name,AGE from mixcase;

结果:查询不可通过。ORA-00904: "AGE": invalid identifier

select "NAme","Age" from mixcase;

结果:查询可通过。

TIP:

一般我们很少通过表名称的大小写敏感来区分两个表,所以我们应该在创建表的时候尽量不要使用引号。这样就可以做到表名称大小写不敏感。

0 0
原创粉丝点击