在 Oracle DB 中创建表时出现错误“%s: invalid identifier”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12676082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error "%s: invalid identifier" occurs when I create a table in Oracle DB
提问by user1712088
when I create a table like this:
当我创建这样的表时:
create table DBDI_HIREDETAIL(
HireID int not null,
EquipID int not null,
Quantity int,
TotalFee float,
Comment varchar(200)
);
The error occurs like this:
错误是这样发生的:
Error at Command Line: "TotalFee float" Error report: SQL Error: ORA-00904: : invalid identifier 00904. 00000 - "%s: invalid identifier"
命令行错误:“TotalFee float” 错误报告:SQL 错误:ORA-00904::标识符无效 00904。00000 -“%s:标识符无效”
I don't understand why my code has an error, it seems to be fine.
我不明白为什么我的代码有错误,似乎没问题。
回答by Ben
COMMENT
is a reserved word in Oracle; it's used for adding commentsto the data dictionary. You should avoid using this as a column name.
COMMENT
是 Oracle 中的保留字;它用于向数据字典添加注释。您应该避免使用它作为列名。
SQL> create table a ( comment number );
create table a ( comment number )
*
ERROR at line 1:
ORA-00904: : invalid identifier
If you reallywant to use this column name you're have to quote it, i.e. "COMMENT"
:
如果你真的想使用这个列名,你必须引用它,即"COMMENT"
:
SQL> create table a ( "COMMENT" number );
Table created.
I would recommend you not doing this as you have to quote the column everywhere.
我建议您不要这样做,因为您必须在各处引用该列。
回答by Frank Schmitt
That's because COMMENT is a reserved word in SQL - use another column name (like HIREDETAIL_COMMENT) instead:
那是因为 COMMENT 是 SQL 中的保留字 - 请改用另一个列名(如 HIREDETAIL_COMMENT):
create table DBDI_HIREDETAIL(
HireID int not null,
EquipID int not null,
Quantity int,
TotalFee float,
HireDetail_Comment varchar(200)
);