无法在Oracle Developer中创建表

时间:2014-11-24 18:35:42

标签: sql database oracle

您好我是SQL新手并且在创建表时遇到问题。 我过去两天一直在看这个代码,我似乎无法让它工作。它一直给我“ORA-00907:错过右括号”我知道这是一个很多但是由于某种原因出现的主题,但我看到的所有例子都没有帮助过我。有人可以告诉我为什么我得到这个错误,我该如何解决它。我很确定它与我的括号无关,也许是我的反对意见 这是我的代码

create TABLE Employee
(
EmployeeID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Phone INT(10) NOT NULL,
JobTitle VARCHAR(10) NOT NULL
);


create TABLE Airplane
(
AirplaneID VARCHAR(10) PRIMARY KEY,
Capacity INT(1000) NOT NULL,
Modle VARCHAR(10) NOT NULL
);


create TABLE Route
(
FlightID VARCHAR(10) PRIMARY KEY,
Origin VARCHAR(20) NOT NULL,
Destination VARCHAR(20) NOT NULL,
ETD INT(10) NOT NULL,
ETA INT(10) NOT NULL
);


create TABLE Customer
(
CustomerID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(10) NOT NULL,
PhoneNumber INT(30) NOT NULL
);


create TABLE Maintenance
(
MaintenanceID VARCHAR(20) PRIMARY KEY,
MaintenanceDate date NOT NULL,
AirplaneID VARCHAR(10) NOT NULL,
EmployeeID VARCHAR(10) NOT NULL,
FOREIGN KEY (AirplaneID) REFERENCES Airplane(AirplaneID),
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID)
);

create TABLE Flight
(
FlightID VARCHAR(10),
FlightDate date,
AirplaneID VARCHAR(10),
ATD INT(10) NOT NULL,
ATA INT(10) NOT NULL,
FOREIGN KEY (FlightID) REFERENCES Flight(FlightID),
FOREIGN KEY (AirplaneID) REFERENCES Airplane(AirplaneID),
CONSTRAINT PK_FlightID PRIMARY KEY (FlightID,FlightDate)
);



create TABLE Reservation
(
ReservationID VARCHAR(20) PRIMARY KEY,
CustomerID VARCHAR(10) NOT NULL,
FlightID VARCHAR(10) NOT NULL,
FlightDate date NOT NULL,
Fare float,
PaymentMethod VARCHAR(20),
CardNumber INT(30) NOT NULL,
ExperationDate date,
check (PaymentMethod = "Cash" OR PaymentMethod ="Credit" OR PaymentMethod 
="Cheque",
FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID),
FORIGN KEY (FlightID,FlightDate) REFERENCES Flight(FlightID,FlightDate)
);

create TABLE CrewResveration
(
EmployeeID VARCHAR(10),
FlightID VARCHAR(10),
FlightDate date NOT NULL,
Role VARCHAR(20) NOT NULL,
ShiftHour INT(10) NOT NULL,
FORIGN KEY (FlightID,FlightDate) REFERENCES Flight(FlightID,FlightDate)
FORIGNKEY (EmployeeID) REFERENCES Employee(EmployeeID) 
CONSTRAINT PK_CrewAssignment PRIMARY (FlightID,FlightDate,EmployeeID)
);

以下是我运行代码时得到的结果:

Error starting at line : 1 in command -
create TABLE Employee
(
EmployeeID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(30) NOT NULL,
Phone INT(20) NOT NULL,
JobTitle VARCHAR(10) NOT NULL
)
Error at Command Line : 5 Column : 10
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:
Error starting at line : 10 in command -
create TABLE Airplane
(
AirplaneID VARCHAR(10) PRIMARY KEY,
Capacity INT(1000) NOT NULL,
Modle VARCHAR(10) NOT NULL
)
Error at Command Line : 13 Column : 13
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:
Error starting at line : 18 in command -
create TABLE Route
(
FlightID VARCHAR(10) PRIMARY KEY,
Origin VARCHAR(20) NOT NULL,
Destination VARCHAR(20) NOT NULL,
ETD INT(10) NOT NULL,
ETA INT(10) NOT NULL
)
Error at Command Line : 23 Column : 8
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:
Error starting at line : 28 in command -
create TABLE Customer
(
CustomerID VARCHAR(10) PRIMARY KEY,
Name VARCHAR(10) NOT NULL,
PhoneNumber INT(30) NOT NULL
)
Error at Command Line : 32 Column : 16
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:
Error starting at line : 36 in command -
create TABLE Maintenance
(
MaintenanceID VARCHAR(20) PRIMARY KEY,
MaintenanceDate date NOT NULL,
AirplaneID VARCHAR(10) NOT NULL,
EmployeeID VARCHAR(10) NOT NULL,
FOREIGN KEY (AirplaneID) REFERENCES Airplane(AirplaneID),
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID)
)
Error at Command Line : 42 Column : 37
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:
Error starting at line : 46 in command -
create TABLE Flight
(
FlightID VARCHAR(10),
FlightDate date,
AirplaneID VARCHAR(10),
ATD INT(10) NOT NULL,
ATA INT(10) NOT NULL,
FOREIGN KEY (FlightID) REFERENCES Flight(FlightID),
FOREIGN KEY (AirplaneID) REFERENCES Airplane(AirplaneID),
CONSTRAINT PK_FlightID PRIMARY KEY (FlightID,FlightDate)
)
Error at Command Line : 51 Column : 8
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:
Error starting at line : 60 in command -
create TABLE Reservation
(
ReservationID VARCHAR(20) PRIMARY KEY,
CustomerID VARCHAR(10) NOT NULL,
FlightID VARCHAR(10) NOT NULL,
FlightDate date NOT NULL,
Fare float,
PaymentMethod VARCHAR(20),
CardNumber INT(30) NOT NULL,
ExperationDate date,
check (PaymentMethod = "Cash" OR PaymentMethod ="Credit" OR PaymentMethod 
="Cheque",
FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID),
FORIGN KEY (FlightID,FlightDate) REFERENCES Flight(FlightID,FlightDate)
)
Error at Command Line : 68 Column : 15
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:
Error starting at line : 76 in command -
create TABLE CrewResveration
(
EmployeeID VARCHAR(10),
FlightID VARCHAR(10),
FlightDate date NOT NULL,
Role VARCHAR(20) NOT NULL,
ShiftHour INT(10) NOT NULL,
FORIGN KEY (FlightID,FlightDate) REFERENCES Flight(FlightID,FlightDate)
FORIGNKEY (EmployeeID) REFERENCES Employee(EmployeeID) 
CONSTRAINT PK_CrewAssignment PRIMARY (FlightID,FlightDate,EmployeeID)
)
Error at Command Line : 82 Column : 14
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:

2 个答案:

答案 0 :(得分:0)

问题在于您的数据类型。 INT不是有效的Oracle数据类型。试试这个:

create TABLE Employee ( EmployeeID VARCHAR(10) PRIMARY KEY, 
                        Name VARCHAR(30) NOT NULL, 
                        Phone NUMBER(10) NOT NULL, 
                        JobTitle VARCHAR(10) NOT NULL );

答案 1 :(得分:0)

错误描述具有误导性,但指针(第5行,第10列)在读取“INT”之后完全指向......这是他所不知道的。他应该说他不理解这一点,但他提到了一些带括号的东西,具有讽刺意味的是,它实际上是正确的。不幸的是,它偶尔会出现错误消息的误导,你必须更进一步思考。