oracle ORA-00904: : 无效标识符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4452671/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:11:57  来源:igfitidea点击:

ORA-00904: : invalid identifier

sqloracleoracle10gora-00904

提问by itsaboutcode

I am trying to create a Table in Oracle and getting the error : ORA-00904: : invalid identifier

我正在尝试在 Oracle 中创建一个表并收到错误: ORA-00904: : invalid identifier

Here is my command. I really can't see any problem in it. Please help me to identify the error. Thanks.

这是我的命令。我真的看不出有什么问题。请帮我找出错误。谢谢。

CREATE TABLE Sale (
CustomerId INT NOT NULL ,
BarCode INT NOT NULL ,
SalesId INT NOT NULL ,
Date DATE NULL ,
CheckOut TINYINT(1) NULL ,
PRIMARY KEY (CustomerId, BarCode, SalesId) ,
CONSTRAINT fk_Customer_has_Product_Customer
FOREIGN KEY (CustomerId )
REFERENCES Customer (CustomerId )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_Customer_has_Product_Product1
FOREIGN KEY (BarCode )
REFERENCES Product (BarCode )
ON DELETE NO ACTION
ON UPDATE NO ACTION);

回答by Tony Andrews

The maximum length for an Oracle identifier is 30 characters. These exceed that, are 32 chars long:

Oracle 标识符的最大长度为 30 个字符。这些超过了,是 32 个字符长:

  • fk_Customer_has_Product_Customer
  • fk_Customer_has_Product_Product1
  • fk_Customer_has_Product_Customer
  • fk_Customer_has_Product_Product1

See Schema Object Naming Rules

请参阅架构对象命名规则

回答by Harrison

As previously mentioned, change "DATE" to something more descriptive and not reserved. also, it seems TINYINTdoes not work in a table create so change that to NUMBER(1), as well as Tony's correct suggestion of reducing the name size (<=30 chrs)

如前所述,将“日期”更改为更具描述性而非保留的内容。此外,似乎TINYINT在表中不起作用,因此将其更改为 NUMBER(1),以及 Tony 减少名称大小的正确建议 (<=30 chrs)

CREATE TABLE Sale
(
    CustomerId INT NOT NULL                    ,
    BarCode    INT NOT NULL                    ,
    SalesId    INT NOT NULL                    ,
    SaleDate DATE NULL                    , --DATE is reserved, changed to SaleDate
    CheckOut number(1) NULL               , --tinyint(1) did not work so changed to number(1)
    PRIMARY KEY( CustomerId, BarCode, SalesId )     ,
    CONSTRAINT fk_SaleCustCusID FOREIGN KEY( CustomerId ) REFERENCES Customer( CustomerId ) ON
    DELETE NO ACTION ON
    UPDATE NO ACTION,
    CONSTRAINT fk_SaleCustBarCode FOREIGN KEY( BarCode ) REFERENCES Product( BarCode ) ON
    DELETE NO ACTION ON
    UPDATE NO ACTION
);