简体   繁体   English

更改Oracle表:无效的标识符

[英]Altering Oracle table: invalid identifier

Using Oracle Application Express for Oracle 11g 使用Oracle Application Express for Oracle 11g

Adding a foreign key constraint to a preexisting table. 将外键约束添加到预先存在的表。

Table: COMMUNICATION 表:沟通

COMMUNICATION-ID      NUMBER        
COMMUNICATIONTYPE_ID  VARCHAR2(6)   
CONTACT_ID            NUMBER         
COMMUNICATIONVALUE    VARCHAR2(40)

Table: COMMUNICATIONTYPE 表:COMMUNICATIONTYPE

COMMUNICATIONTYPE-ID VARCHAR2(6)


Using the following SQL in the SQL Command Interface 在SQL命令界面中使用以下SQL

ALTER TABLE COMMUNICATION
ADD CONSTRAINT FK_COMMUNICATIONTYPE
FOREIGN KEY (COMMUNICATIONTYPE_ID)
REFERENCES COMMUNICATIONTYPE(COMMUNICATIONTYPE-ID)

Returns the following: 返回以下内容:

ORA-00904: : invalid identifier ORA-00904 ::无效的标识符

Didn't think this could be any simpler. 没想到这可能更简单。 What on earth could be going wrong? 到底怎么会出错?

Are you sure the field is called COMMUNICATIONTYPE-ID ? 您确定该字段名为COMMUNICATIONTYPE-ID吗?

- is not normally used in identifiers as it has special meaning. -通常不在标识符中使用,因为它具有特殊含义。

If I were you I would rename the column COMMUNICATIONTYPE_ID 如果我是你,我会重命名列COMMUNICATIONTYPE_ID

To use it in an identifier you need to always surround that identifier in double quotes. 要在标识符中使用它,您需要始终用双引号括起该标识符。

ALTER TABLE COMMUNICATION
ADD CONSTRAINT FK_COMMUNICATIONTYPE
FOREIGN KEY (COMMUNICATIONTYPE_ID)
REFERENCES COMMUNICATIONTYPE("COMMUNICATIONTYPE-ID")

COMMUNICATIONTYPE(COMMUNICATIONTYPE-ID)

Dash is not valid in Oracle names. Dash在Oracle名称中无效。 I think you meant to type an underscore. 我想你打算输入一个下划线。 It's easily done. 它很容易完成。

As the DDL for the COMMUNICATION table the same typo that create table script may have failed as well. 作为COMMUNICATION表的DDL, create table脚本的相同拼写错误也可能失败。 So the error could have been thrown in more than one place. 因此错误可能会被抛到多个地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM