ORA-00911:无效字符

时间:2015-01-21 02:39:29

标签: oracle oracle10g

我正在尝试编写带有列定义的第一个表创建脚本。我已经尝试了几件事来让这个错误消失,但无济于事。请查看下面的代码中是否有任何明显的内容:

CREATE TABLE CD_TYPE (
CD_TYPE VARCHAR2(4) PRIMARY KEY,
CD_FORMAT VARCHAR2(10) 
);

CREATE TABLE MANUFACTURER (
MANUFACTURER_NUM NUMBER(3) PRIMARY KEY,
MANUFACTURER_NAME VARCHAR2(30) 
);

CREATE TABLE CD_TITLE (
CD_NUM    NUMBER(4) PRIMARY KEY,
TITLE   VARCHAR2(30),
MANUFACTURER_NUM VARCHAR2(30) FOREIGN KEY,
CD_TYPE   VARCHAR2(4) FOREIGN KEY,
ACQUIRED_DATE DATE,
ORIGINAL CHAR(1) 
);

CREATE TABLE CD_SN (
CD_NUM NUMBER(4) PRIMARY KEY FOREIGN KEY,
SERIAL_NUM VARCHAR2(30) PRIMARY KEY,
NUM_LIC_REMAIN NUMBER(2) 
);

1 个答案:

答案 0 :(得分:0)

问题在于读取列

 MANUFACTURER_NUM VARCHAR2(30) FOREIGN KEY,

您忘记指定这些列引用的表格。

您使用REFERENCES子句:

create table cd_title (
cd_num    number(4) primary key,
title   varchar2(30),
manufacturer_num             REFERENCES MANUFACTURER,
cd_type                      REFERENCES CD_TYPE,
acquired_date date,
original char(1)
);

或者,您可以使用CONSTRAINT ... FOREIGN KEY (...) REFERENCES ...子句指定外键的名称:

create table cd_title (
cd_num    number(4) primary key,
title   varchar2(30),
manufacturer_num,
cd_type,
acquired_date date,
original char(1),
--
CONSTRAINT cd_title_fk1 FOREIGN KEY (manufacturer_num) REFERENCES manufacturer,
CONSTRAINT cd_title_fk2 FOREIGN KEY (cd_type         ) REFERENCES cd_type
)