Search notes:

ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view

ANSI join vs traditional joins

Create two tables that will later be joined in a materialized view:
create table tq84_A (
   id  varchar2( 5) primary key,
   txt varchar2(10)
);

create table tq84_B (
   id    references tq84_A,
   val_1 number,
   val_2 number
)
The following materialized view joins these two tables with an ANSI join. The materialized view is created without any error:
create materialized view tq84_MV
   refresh complete on commit
as  
select
   a.id,
   sum(b.val_1) sum_val_1
from
   tq84_A a                 join
   tq84_B b on a.id = b.id
group by
   a.id;
Trying to create the following materialized view with a subquery throws an ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view error:
create materialized view tq84_MV_subquery
   refresh complete on commit
as  
select
   id,
   sum_val_1
from (
   select
      a.id,
      sum(b.val_1) sum_val_1
   from
      tq84_A a                 join
      tq84_B b  on a.id = b.id
   group by
      a.id
);
It turns out that this error is not thrown anymore if the subquery joins these tables with a «traditional» join:
create materialized view tq84_MV_subquery
   refresh complete on commit
as  
select
   id,
   sum_val_1
from (
select
   a.id,
   sum(b.val_1) sum_val_1
from
   tq84_A a,
   tq84_B b
where
   a.id = b.id
group by
   a.id
);
Testing the materialized view:
insert into tq84_A values ('A', 'aaa' );
insert into tq84_A values ('B', 'bbbb');
insert into tq84_B values ('A', 5, 1);
insert into tq84_B values ('A', 6, 2);

commit;

select * from tq84_MV;
select * from tq84_MV_subquery
Cleaning up:
drop materialized view tq84_MV_subquery;
drop materialized view tq84_MV;
drop table tq84_B;
drop table tq84_A;

See also

materialized view
ORA-12051: ON COMMIT attribute is incompatible with other options
MOS note 101705.1
Other Oracle error messages

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1740464748, '3.12.151.11', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/errors/ORA-12054_cannot-set-the-ON-COMMIT-refresh-attribute-for-the-materialized-view(131): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78