ORA-00907: 创建外键 Oracle 12c 时缺少右括号

本教程将介绍ORA-00907: 创建外键 Oracle 12c 时缺少右括号的处理方法,这篇教程是从别的地方看到的,然后加了一些国外程序员的疑问与解答,希望能对你有所帮助,好了,下面开始学习吧。

ORA-00907: 创建外键 Oracle 12c 时缺少右括号 教程 第1张

问题描述

我想制作一个包含一个自动生成的主键和两个外键的表,但我遇到了这个错误......

创建表格答案(默认在null上生成的id号作为身份主键, question_id number 外键引用问题(id), user_id number 外键引用 users(id), 回答 varchar(1000), post_date 日期);创建表答案(默认在 null 上生成的 ID 号作为身份主键,question_id 号外键引用问题(id),user_id 号外键引用用户(id),答案 varchar(1000),post_date 日期)

第 1 行的错误:ORA-00907: 缺少右括号

然后,我尝试了这个:

创建表格答案(默认在null上生成的id号作为身份主键, question_id 编号外键 (question_id) 引用问题(id), user_id number 外键(user_id) 引用users(id), 回答 varchar(1000), post_date 日期);创建表答案(默认在null上生成的id号作为身份主键, question_id 编号外键 (question_id) 引用问题(id), user_id number 外键(user_id) 引用users(id), 回答 varchar(1000), post_date 日期)*

第 1 行的错误:ORA-00907: 缺少右括号

仍然报同样的错误!

但是,如果我分两步进行:

创建表格答案(默认在null上生成的id号作为身份主键, question_id 编号不为空, user_id 编号不为空, 回答 varchar(1000), post_date 日期);表已创建.更改表答案添加外键(question_id)引用问题(id)添加外键(user_id)引用用户(id);

表已更改.

任何人都可以帮我解决这个问题吗?

解决方案

在将内联约束定义为列定义的一部分时,您不需要说 foreign key:

创建表格答案(默认在null上生成的id号作为身份主键, question_id 编号参考问题(id), user_id number 引用 users(id), 回答 varchar(1000), post_date 日期);

祝你好运.

I Want To Make a Table Which Include One Auto Generated Primary Key And Two Foreign Keys But I'm Facing This Error...

create table answers
( id number generated by default on null as identity primary key
, question_id number foreign key references questions(id)
, user_id number foreign key references users(id)
, answer varchar(1000)
, post_date date);

create table answers (id number generated by default on null as identity primary key, question_id number foreign key references questions(id), user_id number foreign key references users(id), answer varchar(1000), post_date date)

ERROR at line 1:
ORA-00907: missing right parenthesis

Then, I tried this:

create table answers
( id number generated by default on null as identity primary key
, question_id number foreign key (question_id) references questions(id)
, user_id number foreign key (user_id) references users(id)
, answer varchar(1000)
, post_date date );

create table answers
( id number generated by default on null as identity primary key
, question_id number foreign key (question_id) references questions(id)
, user_id number foreign key (user_id) references users(id)
, answer varchar(1000)
, post_date date )
  *

ERROR at line 1:
ORA-00907: missing right parenthesis

It is still Giving Same Error!

But, if I do it in two steps:

create table answers
( id number generated by default on null as identity primary key
, question_id number not null
, user_id number not null
, answer varchar(1000)
, post_date date );

Table created.

alter table answers
add foreign key (question_id) references questions(id) add foreign key (user_id) references users(id);

Table altered.

Can anyone please get me out of this?

解决方案

When defining the constraint in-line as part of the column definition you don't need to say foreign key:

create table answers
( id number generated by default on null as identity primary key
, question_id number references questions(id)
, user_id number references users(id)
, answer varchar(1000)
, post_date date);

Best of luck.

好了关于ORA-00907: 创建外键 Oracle 12c 时缺少右括号的教程就到这里就结束了,希望趣模板源码网找到的这篇技术文章能帮助到大家,更多技术教程可以在站内搜索。