oracle中如何给物化视图添加主键

How to add primary key to materialized view in oracle

请帮我举例说明如何在 oracle 19c 或 21c 中将主键添加到物化视图。 此外,现实生活中我们使用主键来实现物化视图的应用程序。我在完成对物化视图的研究后发布了这个。 我强烈认为物化视图不需要主键。如有不妥请指正

如何添加主键?使用 ALTER TABLE 语句。

这是一个示例table;我将在其上创建实体化视图。

SQL> create table test as
  2    select deptno, empno, ename, job
  3    from emp;

Table created.

SQL> create materialized view mv_test as
  2    select deptno, empno, ename, job
  3    from test;

Materialized view created.

主键:

SQL> alter table mv_test add constraint pk_mvt primary key (empno);

Table altered.

SQL>

现实生活:适时使用。主键 隐式地 在主键列上创建索引。索引提高性能(如果优化器选择使用它)。