Add column to materialized view

4.5k views Asked by At

I have an existing materialized view in Oracle. But I want to add more columns to it. I saw that it is not possible to execute CREATE OR REPLACE to the materialized view so how can I do that ?

Thanks!

2

There are 2 answers

0
AudioBubble On

Add the columns to the base table and after that run a refresh in the MV.

declare
begin
  DBMS_SNAPSHOT.REFRESH('your_mv', 'f');
end;
0
Pedro Sanches On
select * from dba_objects where status='INVALID';

grant create materialized view to <schema>;
grant create table to <schema>;

drop MATERIALIZED VIEW <schema>.<mvname>;

  CREATE MATERIALIZED VIEW <schema>.<mvname>
  (...)
  AS SELECT (...);

select * from  <schema>.<mvname>;


revoke create materialized view from <schema>;
revoke create table from <schema>;

select * from dba_objects where status='INVALID';