Oracle关键字
通过PD建模,生成SQL语句导入Oracle中执行,生成表都没有问题。但是在删除,添加记录的过程中老是抛出异常,比如“表或视图不存在”;
这是生成的PL\SQL语句:
1 /*==============================================================*/ 2 /* Table: "Branch" */ 3 /*==============================================================*/ 4 create table "Branch" 5 ( 6 "Branch_id" INTEGER not null, 7 "Branch_name" NVARCHAR2(32), 8 "Type" NVARCHAR2(32), 9 Y BINARY_DOUBLE, 10 X BINARY_DOUBLE, 11 "Mark" NVARCHAR2(256), 12 constraint PK_BRANCH primary key ("Branch_id") 13 ); 14 15 /*==============================================================*/ 16 /* Table: "CurrentBranchStatistic" */ 17 /*==============================================================*/ 18 create table "CurrentBranchStatistic" 19 ( 20 "Branch_id" INTEGER, 21 "Number" INTEGER 22 );
可以看到表名和字段名都被加了双引号,而且有些字段还用了关键字,如Number,Type
通过v$reserved_words视图可以查看关键字信息。
以system用户登录:
select * from v$reserved_words ;
可以查询到1700多条记录
字段类型及解释:Column Datatype Description
KEYWORD VARCHAR2(30): Name of the keyword
LENGTH NUMBER: Length of the keyword
RESERVED VARCHAR2(1) :A value of Y means that the keyword cannot be used as an identifier. A value of N means that it is not reserved.
Y表示该关键字是保留字,不能用作标示符
RES_TYPE VARCHAR2(1) :A value of Y means that the keyword cannot be used as a type name. A value of N means that it is not reserved.
RES_ATTR VARCHAR2(1) :A value of Y means that the keyword cannot be used as an attribute name. A value of N means that it is not reserved.
RES_SEMI VARCHAR2(1) :A value of Y means that the keyword is not allowed as an identifier in certain situations, such as in DML. A value of N means that it is not reserved. 值为Y表示关键字在特定情况下不允许作为标示符,比如DML(数据库操纵语言)
DUPLICATE VARCHAR2(1) :A value of Y means that the keyword is a duplicate of another keyword. A value of N means that it is not a duplicate.
1.Oracle有许多保留字(Reserved Words)和关键字(Keywords),其区别是保留字不可以用来作为标识符, 关键字可以用来作为标识符,但不建议使用。
2.一般保留字不能用做对象名。如果一定要用可以加双引号。
查询:select * from v$reserved_words where RESERVED='Y';结果如下
|
查询:select * from v$reserved_words where RES_SEMI='Y';结果如下:
|
测试如下代码:
create table MY_BOX
(
ID NUMBER(10) not null,
COLUMNS NUMBER(5),
Rows NUMBER(5)
)
Rows报错,查询
可以看出ID、COLUMNS、ROWS、NUMBER、TYPE都是关键字,但是NUMBER是保留字,ROWS特定条件下不能做标识符。
参考文档:
http://air-house.iteye.com/blog/868118
http://blog.sina.com.cn/s/blog_6d6e54f70100tsdw.html