oracle 字段 大小写问题
2012-05-24 12:30
330 查看
今天create一个表的时候, 字段加了引号,结果select 该字段的时候告诉字段找不着,示例如下:
经反复实验,如果建表时字段不加引号,则无论怎么查询都不会出现上述问题,后证明是大小写问题. 继续实验:
具体如下:
id=ID="ID" 第1个id默认转换成大写ID, 第二个ID也默认转换成大写ID, 第三个不作转换, 由于引号引住,本身就是大写, 所以三个相等.
≠ (上面一行不等于下面一行)
[b]"id"="id" [/b]第1个"id"由于是引号引住,并且是小写, 所以引用该字段时只能用"id"引用,其它任何形式都会报错.
结论: oracle 的字段, 在不加引号时, 全部默认转换成大写.
加引号时, 则不会自动转换, 写成什么样就是什么样, 在引用该字段时,如果大小写不匹配则报错 ORA-00904: "id": invalid identifier
由于存在上述特性,则可能出现2个字段名称一样的现象, 如下:
SQL> create table test("id" varchar2(10)); 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 at line 1: ORA-00904: "ID": invalid identifier SQL> select "id" from test; id ---------- 1 SQL> select * from test; id ---------- 1 SQL>
经反复实验,如果建表时字段不加引号,则无论怎么查询都不会出现上述问题,后证明是大小写问题. 继续实验:
SQL> create table test(id varchar2(10)); 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>
具体如下:
id=ID="ID" 第1个id默认转换成大写ID, 第二个ID也默认转换成大写ID, 第三个不作转换, 由于引号引住,本身就是大写, 所以三个相等.
≠ (上面一行不等于下面一行)
[b]"id"="id" [/b]第1个"id"由于是引号引住,并且是小写, 所以引用该字段时只能用"id"引用,其它任何形式都会报错.
结论: oracle 的字段, 在不加引号时, 全部默认转换成大写.
加引号时, 则不会自动转换, 写成什么样就是什么样, 在引用该字段时,如果大小写不匹配则报错 ORA-00904: "id": invalid identifier
由于存在上述特性,则可能出现2个字段名称一样的现象, 如下:
SQL> drop table test; Table dropped. SQL> create table test("id" varchar2(10), id varchar2(10)); Table created. SQL> desc test; Name Null? Type ----------------------------------------- -------- ---------------------------- id VARCHAR2(10) ID VARCHAR2(10) SQL> insert into test values('3','3'); 1 row created. SQL> select * from test; id ID ---------- ---------- 3 3
相关文章推荐
- oracle添加字段引起的问题
- MySQL与Oracle的大小写问题
- 【转】FireBird里定义字段的大小写问题
- 【网络转载】Weblogic数据源引发的Oracle-Clob字段问题
- ORACLE的ALL_VIEWS数据字典text字段long类型问题
- Mysql中字段大小写敏感问题
- ORACLE的VARCHAR2字段类型占字节问题
- 修正RO6.0.43中Oracle取字段长度不正确的问题.
- oracle中的timestamp字段的值乱码问题修改
- 2005-01-24 oracle中blob字段下载后的乱码问题
- oracle密码大小写问题
- oracle insert数据标识符无效问题 oracle ORA-00904: "字段名": 标识符无效
- 解决比较Oracle中CLOB字段问题
- 关于Oracle检索字段值小数点前面0不显示问题
- 折腾Oracle问题小菜记[分页存储过程/查询所有表、视图、存储过程/查询表、视图、存储过程字段结构与参数](三)
- SQL语句大小写是否区分的问题,批量修改整个数据库所有表所有字段大小写
- Oracle利用Function 执行动态脚本解决将脚本存在字段中的问题
- Oracle解决导入CLOB大字段数据失败的问题
- hibernate 中反射oracle的Date字段问题
- 关于oracle 数据库中字符字段的排序问题