Oracle SQL 错误 ORA-00907:缺少右括号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15823563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle SQL error ORA-00907: missing right parenthesis
提问by Bilal Haider
How are you all?
你们好吗?
Basically I've written up this bit of SQL code to create a table but I keep getting the error stated in the title, any idea as to why?
基本上我已经编写了这段 SQL 代码来创建一个表,但我一直收到标题中所述的错误,知道为什么吗?
Here's the code:
这是代码:
CREATE TABLE staff(
staffID INT NOT NULL PRIMARY KEY,
firstName VARCHAR2(20),
lastName VARCHAR2(20),
addressLine_1 VARCHAR2(30),
city VARCHAR2(15),
postcode VARCHAR2(7),
telephone VARCHAR2(15),
salary DECIMAL (19,4),
branchID INT FOREIGN KEY REFERENCES branches(branchID)
);
Also here is the code for my 'branches' table
这也是我的“分支”表的代码
CREATE TABLE branches
(branchID int NOT NULL PRIMARY KEY,
addressLine_1 VARCHAR2(30),
city VARCHAR2(15),
postcode VARCHAR2(7),
telephone VARCHAR2(15),
manager VARCHAR2(20));
Any help would be appreciated!
任何帮助,将不胜感激!
Thank you!
谢谢!
回答by Taryn
A few suggestions:
几点建议:
First make sure that the branches
table has been created.
首先确保branches
表已创建。
Second, I would alter the create table code to the following:
其次,我将创建表代码更改为以下内容:
CREATE TABLE staff(
staffID INT NOT NULL PRIMARY KEY,
firstName VARCHAR(20),
lastName VARCHAR(20),
addressLine_1 VARCHAR2(30),
city VARCHAR2(15),
postcode VARCHAR2(7),
telephone VARCHAR2(15),
salary DECIMAL (19,4),
branchID INT,
constraint fk_branchId FOREIGN KEY (branchID) REFERENCES branches(branchID)
);
See SQL Fiddle with Demo. The syntax to create a FOREIGN KEYduring table creation is:
请参阅SQL Fiddle with Demo。在表创建期间创建FOREIGN KEY的语法是:
CREATE TABLE table_name
(
column1 datatype null/not null,
column2 datatype null/not null,
...
CONSTRAINT fk_column
FOREIGN KEY (column1, column2, ... column_n)
REFERENCES parent_table (column1, column2, ... column_n)
);
回答by CHAITANYA
Here is the creation of table staff1
这是表staff1的创建
CREATE TABLE staff
(
staffID INT NOT NULL PRIMARY KEY,
firstName VARCHAR2(20),
lastName VARCHAR2(20),
addressLine_1 VARCHAR2(30),
city VARCHAR2(15),
postcode VARCHAR2(7),
telephone VARCHAR2(15),
branchID int,
salary DECIMAL (19,4),
CONSTRAINT BRANCH_fk FOREIGN KEY(branchID) REFERENCES branches(branchID)
)
SQL> /
Table created.
Please use constraint name such that finding an error becomes easy.
请使用约束名称,以便轻松查找错误。
回答by abode
create table medication (
id int not null primary key,
name varchar(20),
mudslig price number (10),
protect date not null default (getdate()),
finish date not null default (getdate()),
company proect varchre2 (20),
shelf id int,
chemistid int,
constraint shelf_fk foreign key (shelf id) refences shelf (shelf id),
constraint chemist_fk foreign key (chemistid) refences chemist (chemistid)
);
Please use constraint name such that finding an error becomes easy.
请使用约束名称,以便轻松查找错误。