“ORA-00922:缺少或无效选项”SQL create table错误

时间:2015-11-05 21:10:07

标签: sql oracle

    CREATE TABLE sales_invoice -- missing or invalid option
        (sales_invoice_no                 NUMBER(6) NOT NULL
            CONSTRAINT sales_invoice_no_pk PRIMARY KEY
       , cust_id                         NUMBER(6) NOT NULL
       ,   CONSTRAINT sales_cust_invoice_fk FOREIGN KEY (cust_id)
            REFERENCES customer(cust_id))   
       , art_id                           NUMBER(6) NOT NULL
       ,   CONSTRAINT art_invoice_fk FOREIGN KEY (art_id)
            REFERENCES art_sale(art_id)
       , sales_emp_id                    NUMBER(6) NOT NULL
       ,    CONSTRAINT sales_invoice_emp_fk (sales_emp_id)
            REFERENCES sales_emp(emp_id)
       , manager_emp_id                   NUMBER(6)
       ,   CONSTRAINT manager_invoice_emp_fk (manager_emp_id) 
            REFERENCES manager_emp(emp_id)
       , sales_invoice_amount             NUMBER (10)
            CONSTRAINT sales_amount_check CHECK (sales_invoice_amount > 0 ));

我尝试运行此错误时收到此错误。我正在尝试创建一个从其他几个表中抽取并将其作为销售发票打印的表。提前谢谢。

2 个答案:

答案 0 :(得分:1)

您的格式化使我更难发现错误。我重新格式化了您的代码,并在您的“sales_cust_invoice_fk”约束后找到了额外的“)”。这是重新格式化的代码:

 CREATE TABLE sales_invoice (
sales_invoice_no    NUMBER(6) NOT NULL CONSTRAINT sales_invoice_no_pk PRIMARY KEY
cust_id         NUMBER(6) NOT NULL,
art_id          NUMBER(6) NOT NULL,
sales_emp_id        NUMBER(6) NOT NULL,
manager_emp_id      NUMBER(6),
sales_invoice_amount    NUMBER (10),
CONSTRAINT sales_cust_invoice_fk FOREIGN KEY (cust_id) REFERENCES customer(cust_id), 
CONSTRAINT art_invoice_fk FOREIGN KEY (art_id) REFERENCES art_sale(art_id),
CONSTRAINT sales_invoice_emp_fk (sales_emp_id) REFERENCES sales_emp(emp_id),
CONSTRAINT manager_invoice_emp_fk (manager_emp_id) REFERENCES manager_emp(emp_id),
CONSTRAINT sales_amount_check CHECK (sales_invoice_amount > 0 )
);

答案 1 :(得分:0)

这是查询

CREATE TABLE sales_invoice 
        (sales_invoice_no                 NUMBER(6) NOT NULL
            CONSTRAINT sales_invoice_no_pk PRIMARY KEY
       , cust_id                         NUMBER(6) NOT NULL
       ,   CONSTRAINT sales_cust_invoice_fk FOREIGN KEY (cust_id)
            REFERENCES customer(cust_id)   
       , art_id                           NUMBER(6) NOT NULL
       ,   CONSTRAINT art_invoice_fk FOREIGN KEY (art_id)
            REFERENCES art_sale(art_id)
       , sales_emp_id                    NUMBER(6) NOT NULL
       ,    CONSTRAINT sales_invoice_emp_fk FOREIGN KEY (sales_emp_id)
            REFERENCES sales_emp(emp_id)
       , manager_emp_id                   NUMBER(6)
       ,   CONSTRAINT manager_invoice_emp_fk FOREIGN KEY (manager_emp_id) 
            REFERENCES manager_emp(emp_id)
       , sales_invoice_amount             NUMBER (10)
            CONSTRAINT sales_amount_check CHECK (sales_invoice_amount > 0 ));