1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| DROP MATERIALIZED VIEW LOG ON t_C_1_table
/
DROP MATERIALIZED VIEW vm_t_c
/
drop table t_a
/
drop table t_b
/
drop table t_c_1_table
/
drop table t_ac
/
drop table t_bc
/
create table t_a (a_id int,
a_val varchar2(1),
primary key (a_id)
)
/
create table t_b (b_id int,
b_val varchar2(1),
primary key (b_id)
)
/
CREATE TABLE t_c_1_table
(
c_id int NOT NULL,
c_a_or_b varchar2(1),
c_a_or_b_id int,
PRIMARY KEY (c_id)
)
/
CREATE MATERIALIZED VIEW LOG ON t_c_1_table WITH PRIMARY KEY;
create MATERIALIZED VIEW vm_t_c
REFRESH FAST ON COMMIT
AS
select c_id,
(case when c_a_or_b='a' then c_a_or_b_id else -1 end) as a_id,
(case when c_a_or_b='b' then c_a_or_b_id else -1 end) as b_id
from t_c_1_table
/
alter table vm_t_c add FOREIGN KEY (a_id) REFERENCES t_a(a_id) DEFERRABLE
/
alter table vm_t_c add FOREIGN KEY (b_id) REFERENCES t_b(b_id) DEFERRABLE
/
insert into t_a values (-1,'b');
insert into t_a values (1,'a');
insert into t_a values (2,'a');
insert into t_a values (3,'a');
insert into t_b values (-1,'a');
insert into t_b values (1,'b');
insert into t_b values (2,'b');
insert into t_b values (4,'b');
commit; |
Partager