ORACLE对象名大小写敏感性相关的深入分析

注:
1、 本文是以ORACLE10.2为测试分析版本
2、 本文中提到的ORACLE对像名包括ORACLE中的表名、视图名、字段名、函数名等等。


以下是笔者对创建表及访问使用不同命名方式的一个实例,是笔者的机器上测试结果:

连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

SQL> create table mytable  ( C1 VARCHAR2(6)  );
Table created

insert into mytable values('aer');
SQL> select * from "MYTABLE";
C1
---------------
aer

SQL> select * from MYtable;
C1
---------------
aer

SQL> select * from "mytable";
select * from "mytable"
ORA-00942: 表或视图不存在
SQL> drop table mytable;
Table dropped
SQL>
SQL> create table "mytable" (C1 varchar2(6));

Table created.

SQL> insert into "mytable" values('aer');

1 row created.

SQL> select * from "mytable";
C1
---------------
aer

SQL> select * from mytable;
select * from mytable
              *
ERROR at line 1:
ORA-00942: table or view does not exist

 
SQL> select * from MYTABLE;
select * from MYTABLE
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from "MYTABLE";
select * from "MYTABLE"
              *
ERROR at line 1:
ORA-00942: table or view does not exist


下表为笔者的测试结果汇总:
√表示允许访问,×表示不允许访问。
实例:
读取         mytable MYTABLE "mytable" "MYTABLE"

创建
mytable         √           √               ×             √
MYTABLE     √           √                ×            √
"mytable"      ×           ×               √             ×
"MYTABLE" √           √                ×             √

总结归纳:
读取                      小写字母 大写字母 加引号小写字母 加引号大写字母
创建 
小写字母                    √              √                    ×                         √
大写字母                    √              √                    ×                         √
加引号小写字母        ×              ×                    √                         ×
加引号大写字母        √              √                    ×                         √

以下为根据笔者对ORACLE数据字典及实际测试总结分析结论:
ORACLE在创建对像时如果没有加引号,对存入数据字典时都会将对像名小写字母转换成大写字母存储,如mytable将转换成MYTABLE;如果创建时加了引号,则以引号内的实际字符存储。
访问时如果没加引号则会将小写字母转换成大写字母再访问,如mytable将转换成MYTABLE;如果加了引号则以引号内的实际字符访问。
ORACLE在读取数据字典时只要发现对像名里有小写字母或者是除字母汉字以外开头的字符都认为是大小写敏感的,并且要求在访问时需要加上引号。

建议创建及更新时,表名、视图名、字段名、函数名不要加引号。

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wh62592855/archive/2009/09/24/4589068.aspx

请使用浏览器的分享功能分享到微信等