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开发人员上运行时,它会给我以下错误
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 (
答案 0 :(得分:1)
SESSION
是Oracle保留字,不允许重新定义保留字的含义。
重命名专栏
session
到不是保留字的名称。你应该没事!
参考 - http://docs.oracle.com/cd/B10501_01/appdev.920/a42525/apb.htm
答案 1 :(得分:0)
SESSION是Oracle中的保留关键字。但是,如果要将其用作列名,请使用双引号。因此改变
session VARCHAR2(3),
到
"session" VARCHAR2(3),
否则只需重命名该列。
以下是SQLFiddle