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

ORA-00907: Missing Right Parenthesis On Creating Foreign Key Oracle 12c(ORA-00907: 创建外键 Oracle 12c 时缺少右括号)
本文介绍了ORA-00907: 创建外键 Oracle 12c 时缺少右括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

创建表格答案(默认在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 时缺少右括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)