0
CREATE TABLE students (
Year          NUMBER(4) NOT NULL,
Semester VARCHAR2(1) NOT NULL CONSTRAINT stu_sem_ck CHECK (semester IN ('1', '2', '3')),
department    VARCHAR2(3) NOT NULL,
course_number NUMBER NOT NULL,
session       VARCHAR2(3),
first_name    NVARCHAR2(10),
Middle_name   NVARCHAR2(15),
last_name     NVARCHAR2(15) NOT NULL,
id            NUMBER(9) NOT NULL,
area_code     VARCHAR2(3),
phone_number  VARCHAR2(7),
email_address NVARCHAR2(60),
Street1       NVARCHAR2(20),
street2       NVARCHAR2(20),
city          NVARCHAR2(20),
State_prov    NVARCHAR2(20),
country       CHAR(2),
postal_code   NVARCHAR2(15),
language      CHAR(2),
CONSTRAINT student_pk PRIMARY KEY (id))

在 SQL devloper 上运行时,它给了我以下错误

Error starting at line 2 in command:
CREATE TABLE students (
Year          NUMBER(4) NOT NULL,
Semester VARCHAR2(1) NOT NULL CONSTRAINT stu_sem_ck CHECK (semester IN ('1', '2', '3')),
department    VARCHAR2(3) NOT NULL,
course_number NUMBER NOT NULL,
session       VARCHAR2(3),
first_name    NVARCHAR2(10),
Middle_name   NVARCHAR2(15),
last_name     NVARCHAR2(15) NOT NULL,
id            NUMBER(9) NOT NULL,
area_code     VARCHAR2(3),
phone_number  VARCHAR2(7),
email_address NVARCHAR2(60),
Street1       NVARCHAR2(20),
street2       NVARCHAR2(20),
city          NVARCHAR2(20),
State_prov    NVARCHAR2(20),
country       CHAR(2),
postal_code   NVARCHAR2(15),
language      CHAR(2),
CONSTRAINT student_pk PRIMARY KEY (id))
Error at Command Line:6 Column:1
Error report:
SQL Error: ORA-00904: : invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:
Error starting at line 1 in command:
CREATE TABLE students (
4

2 回答 2

1

SESSION是Oracle保留字,不允许重新定义保留字的含义。

重命名您的列

session

到一个不是保留字的名称。你应该没事!

参考 - http://docs.oracle.com/cd/B10501_01/appdev.920/a42525/apb.htm

于 2013-04-07T21:59:44.893 回答
0

SESSION 是 Oracle 中的保留关键字。但是,如果您想将其用作列名,请使用双引号。因此改变

session       VARCHAR2(3),

"session"       VARCHAR2(3),

否则只需重命名该列。

这是SQLFiddle

于 2013-04-07T21:59:55.497 回答