我是SQL的新手,我似乎找不到为什么我会遇到此错误(缺少正确的括号)

发布于 2025-02-10 19:41:57 字数 826 浏览 1 评论 0原文

这是我要创建的桌子,但我得到了这个错误

第7/34行中的错误:ORA-00907:缺失右括号ORA-06512:在“ SYS.WWV_DBMS_SQL_SQL_PAPEX_220100”,第847行ORA-06512:at“ 。

  1. 行数int int int int int
  2. not not not null, list_price Decimal(10,2)不是零,
  3. 折扣十进制(4,2)NOT NULL默认默认值0,
  4. 主键(Item_id),efirene_id(item_id),
  5. extir keir(item_id) key(order_id)参考订单(order_id),“

这是代码:

 CREATE TABLE order_items (
    order_id INT,
    item_id INT,
    product_id INT NOT NULL,
    quantity INT NOT NULL,
    list_price DECIMAL(10 , 2 ) NOT NULL,
    discount DECIMAL(4 , 2 ) NOT NULL DEFAULT 0,
    PRIMARY KEY (order_id , item_id),
    FOREIGN KEY (order_id)
        REFERENCES orders (order_id),
    FOREIGN KEY (product_id)
        REFERENCES products (product_id)
);

this is the table I am trying to create but I get this error

Error at line 7/34: ORA-00907: missing right parenthesis ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_220100", line 847 ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658 ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_220100", line 833 ORA-06512: at "APEX_220100.WWV_FLOW_DYNAMIC_EXEC", line 1903

  1. quantity INT NOT NULL,
  2. list_price DECIMAL (10, 2) NOT NULL,
  3. discount DECIMAL (4, 2) NOT NULL DEFAULT 0,
  4. PRIMARY KEY (item_id),
  5. FOREIGN KEY (order_id) REFERENCES orders (order_id),"

This is the code:

 CREATE TABLE order_items (
    order_id INT,
    item_id INT,
    product_id INT NOT NULL,
    quantity INT NOT NULL,
    list_price DECIMAL(10 , 2 ) NOT NULL,
    discount DECIMAL(4 , 2 ) NOT NULL DEFAULT 0,
    PRIMARY KEY (order_id , item_id),
    FOREIGN KEY (order_id)
        REFERENCES orders (order_id),
    FOREIGN KEY (product_id)
        REFERENCES products (product_id)
);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余生再见 2025-02-17 19:41:57

有了约束,默认首先,不是null next(请参阅第7行):

SQL> CREATE TABLE order_items (
  2      order_id   INT,
  3      item_id    INT,
  4      product_id INT NOT NULL,
  5      quantity   INT NOT NULL,
  6      list_price DECIMAL(10, 2) NOT NULL,
  7      discount   DECIMAL(4, 2) DEFAULT 0 NOT NULL,   --> here
  8     PRIMARY KEY ( ORDER_ID , ITEM_ID ) ,
  9     FOREIGN KEY ( ORDER_ID ) REFERENCES ORDERS ( ORDER_ID ) ,
 10     FOREIGN KEY ( PRODUCT_ID ) REFERENCES PRODUCTS ( PRODUCT_ID ));

Table created.

SQL>

With constraints, default goes first, not null next (see line #7):

SQL> CREATE TABLE order_items (
  2      order_id   INT,
  3      item_id    INT,
  4      product_id INT NOT NULL,
  5      quantity   INT NOT NULL,
  6      list_price DECIMAL(10, 2) NOT NULL,
  7      discount   DECIMAL(4, 2) DEFAULT 0 NOT NULL,   --> here
  8     PRIMARY KEY ( ORDER_ID , ITEM_ID ) ,
  9     FOREIGN KEY ( ORDER_ID ) REFERENCES ORDERS ( ORDER_ID ) ,
 10     FOREIGN KEY ( PRODUCT_ID ) REFERENCES PRODUCTS ( PRODUCT_ID ));

Table created.

SQL>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文