【问题标题】:SQL Error: ORA-00907: missing right parenthesis 00907. 00000 - "missing right parenthesis"SQL 错误:ORA-00907:缺少右括号 00907。00000 -“缺少右括号”
【发布时间】:2016-10-23 15:10:28
【问题描述】:

我不知道这个语法有什么问题。

create table table3 (
id number,
id_table1 number,
id_table2 number,
area varchar2(130) not null,
status varchar2(20),
additional_info varchar2(100),
data date default sysdate,
responsable varchar2(60) not null,
constraint ck_status_contract check(status in('value1','value2','value3')),
constraint fk_id_table1 references table1 on delete set null,
constraint fk_id_table2 references table2 on delete set null,
constraint pk_id_contract primary key(id)
);

结果是:

SQL 错误:ORA-00907:缺少右括号
00907. 00000 - “缺少右括号”

我使用 OracleXE112_Win64。

【问题讨论】:

    标签: sql oracle oracle11g


    【解决方案1】:

    在您的 FK 上,您需要指定两端受影响的列

    CONSTRAINT fk_column
    FOREIGN KEY (column1, column2, ... column_n)
    REFERENCES parent_table (column1,..)
    

    【讨论】:

    • 这个没有那么暗示性的错误让我分心,没有看到我忘记指定外键。
    【解决方案2】:

    您错过了正确添加外键引用。

    要指定foreign key 约束,您应该使用内联

    CONSTRAINT [constraint_name] FOREIGN KEY(customer_id) REFERENCES [master_table_name]([master_column_name])
    

    查看本教程中的更多示例:What is foreign key?

    资源链接:

    SQL Error: ORA-00907: missing right parenthesis

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-31
      • 2021-01-28
      • 2017-05-28
      • 1970-01-01
      • 2016-02-20
      相关资源
      最近更新 更多