简体   繁体   English

Oracle SQL-ALTER VIEW:ORA-00922:丢失或无效的选项

[英]Oracle SQL - ALTER VIEW : ORA-00922: missing or invalid option

I want to add a primary key constraint to my column, but Oracle gives me the following error message: 我想将主键约束添加到我的列中,但是Oracle给我以下错误消息:

ORA-00922: missing or invalid option ORA-00922:丢失或无效的选项

SQL: SQL:

ALTER VIEW view_my_departments
add CONSTRAINT department_id_pk
    PRIMARY KEY (department_id);

Views do not have constraints. 视图没有约束。 A view is simply a query that is saved with a name. 视图只是一个带有名称保存的查询。 Because it's a query, it returns a result set and is thus interchangeable with a table in terms of queries. 因为它是查询,所以它返回结果集,因此就查询而言可以与表互换。

However, there is no actual data persisted in it. 然而,在它坚持没有实际的数据。 Only tables have data and thus tables may have constraints. 仅表具有数据,因此表可能具有约束。 Find out which table contains department_id (probably called department I'm guessing?) and add the constraint to that using. 找出哪个表包含department_id(可能是我猜中的department_id),并将约束添加到该表中。

ALTER TABLE department
add CONSTRAINT department_id_pk
    PRIMARY KEY (department_id);

Querying a table is like using a sub-query. 查表就像使用一个子查询。

If "myview" is defined as: 如果“ myview”定义为:

select r.a, ro.b, u.c
from registration r
inner join roster ro on r.roster_id = ro.roster_id
inner join user u on u.user_id = ro.user_id

Then the database will interpret the following query 然后数据库将解释以下查询

select a, b, c
from myview
where x = 1

as

select a, b, c
from (select r.a, ro.b, u.c
      from registration r
      inner join roster ro on r.roster_id = ro.roster_id
      inner join user u on u.user_id = ro.user_id)
where x = 1

Here, they must be written with disable clause as it cannot be validated. 在这里,必须使用disable子句编写它们,因为它无法通过验证。

So try, 所以尝试

ALTER VIEW view_my_departments
add CONSTRAINT department_id_pk
    PRIMARY KEY (department_id) disable;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM