在Create Table命令SQL中缺少右括号
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Create Table命令SQL中缺少右括号相关的知识,希望对你有一定的参考价值。
创建下表时,我收到错误消息
ORA-00907:缺少右括号。
create table CustomerOrder (
CustomerOrderNumber NUMBER(15) CONSTRAINT Customer_Order_Number_pk PRIMARY KEY
Customer_Number NUMBER(7), CONSTRAINT Customer_Number_fk FOREIGN KEY,
Order_Date Date(6) CONSTRAINT Order_Date_not_null NOT NULL,
Order_Status VARCHAR2(20) CONSTRAINT Order_Status NOT NULL,
Order_Total NUMBER(20) CONSTRAINT Order_Total NOT NULL
);
客户编号错误: ORA-00907:缺少右括号
create table Work_Order (
Work_Order_Number NUMBER(20) CONSTRAINT Work_Order_Number_pk PRIMARY KEY,
Product_Number NUMBER(20),
Work_Order_Date Date(9) Work_Order_Date_not_null NOT NULL,
Date_Required Date(9) CONSTRAINT Date_Required_not_null NOT NULL,
Date_Completed Date(9) CONSTRAINT Date_Completed_not_null NOT NULL,
Work_Status VARCHAR2(100) CONSTRAINT Work_Status_not_null NOT NULL,
Instruction VARCHAR2(500) CONSTRAINT Instruction_not_null NOT NULL,
CONSTRAINT Product_Number_fk FOREIGN KEY (Product_Number) REFERENCES Product(Product_Number)
);
Work_Order_Date的错误: ORA-00907:缺少右括号
我试着通过在最后放入外键的约束来修复它,但仍然不起作用。
create table Work_Order (
Work_Order_Number NUMBER(20) CONSTRAINT Work_Order_Number_pk PRIMARY KEY,
Product_Number NUMBER(20), CONSTRAINT Product_Number_fk FOREIGN KEY(Product_Number) REFERENCES Product(Product_Number),
Work_Order_Date Date(9) Work_Order_Date_not_null NOT NULL,
Date_Required Date(9) CONSTRAINT Date_Required_not_null NOT NULL,
Date_Completed Date(9) CONSTRAINT Date_Completed_not_null NOT NULL,
Work_Status VARCHAR2(100) CONSTRAINT Work_Status_not_null NOT NULL,
Instruction VARCHAR2(500) CONSTRAINT Instruction_not_null NOT NULL
);
Work_Order_Date的错误: ORA-00907:缺少右括号
为了创建这些表,我需要做些什么改变?我在哪里需要添加括号?
这是关于珠宝店数据库的一个课程。表包含有关业务的信息。
在SQL上运行时的预期结果:
表创建
答案
看起来你需要在列定义之后和CONSTRAINTS之前删除逗号,除非它在最后。它应该是:
CustomerOrderNumber NUMBER(15) CONSTRAINT Customer_Order_Number_pk PRIMARY KEY Customer_Number NUMBER(7) CONSTRAINT
参考https://www.techonthenet.com/oracle/tables/create_table.php
另一答案
如果没有所有的总数并且不明确知道你的目标是什么,这里有一些样本可以帮助你开始
SQL> create table CustomerOrder (
2 CustomerOrderNumber NUMBER(15) ,
3 Customer_Number NUMBER(7),
4 Order_Date Date NOT NULL,
5 Order_Status VARCHAR2(20) NOT NULL,
6 Order_Total NUMBER(20) NOT NULL,
7 CONSTRAINT Customer_Order_Number_pk PRIMARY KEY ( CustomerOrderNumber )
8 );
Table created.
SQL>
SQL> create table Work_Order (
2 Work_Order_Number NUMBER(20),
3 Product_Number NUMBER(20),
4 Work_Order_Date Date NOT NULL,
5 Date_Required Date CONSTRAINT Date_Required_not_null NOT NULL,
6 Date_Completed Date CONSTRAINT Date_Completed_not_null NOT NULL,
7 Work_Status VARCHAR2(100) CONSTRAINT Work_Status_not_null NOT NULL,
8 Instruction VARCHAR2(500) CONSTRAINT Instruction_not_null NOT NULL,
9 CONSTRAINT Work_Order_Number_pk PRIMARY KEY ( Work_Order_Number )
10 );
Table created.
以上是关于在Create Table命令SQL中缺少右括号的主要内容,如果未能解决你的问题,请参考以下文章
在 oracle 10g 中出现错误 .. 错误:- ORA-00907:缺少右括号
SQL 错误:ORA-00907:缺少右括号 00907。00000 -“缺少右括号”