CREATE TABLE tab1(id NUMBER, col1 NUMBER);
-- table TAB1 created.
CREATE TABLE tab2(id NUMBER, col1 NUMBER, col2 NUMBER, col3 NUMBER);
-- table TAB2 created.
INSERT ALL
INTO tab1(id, col1) VALUES (tab1_id, tab1_col1)
INTO tab2(id, col1, col2, col3) VALUES (tab2_id, tab2_col1, tab2_col2, tab2_col3)
SELECT 1 AS tab1_id
, 11 AS tab1_col1
, 1 AS tab2_id
, 21 AS tab2_col1
, 22 AS tab2_col2
, 23 AS tab2_col3
FROM DUAL
;
-- 2 rows inserted.
SELECT * FROM tab1;
-- 1 11
SELECT * FROM tab2;
-- 1 21 22 23
CREATE VIEW tab_vw AS
SELECT tab1.id AS tab1_id
, tab1.col1 AS tab1_col1
, tab2.id AS tab2_id
, tab2.col1 AS tab2_col1
, tab2.col2 AS tab2_col2
, tab2.col3 AS tab2_col3
FROM tab1
JOIN tab2
ON tab1.id = tab2.id
;
-- view TAB_VW created.
SELECT * FROM tab_vw;
-- 1 11 1 21 22 23
CREATE OR REPLACE TRIGGER tab_trg
INSTEAD OF INSERT ON tab_vw
FOR EACH ROW
BEGIN
INSERT INTO tab1(id, col1) VALUES (:new.tab1_id, :new.tab1_col1);
INSERT INTO tab2(id, col1, col2, col3) VALUES (:new.tab2_id, :new.tab2_col1, :new.tab2_col2, :new.tab2_col3);
END;
-- TRIGGER TAB_TRG compiled
INSERT INTO tab_vw
(
tab1_id
, tab1_col1
, tab2_id
, tab2_col1
, tab2_col2
, tab2_col3
)
SELECT 2 AS tab1_id
, 11 AS tab1_col1
, 2 AS tab2_id
, 21 AS tab2_col1
, 22 AS tab2_col2
, 23 AS tab2_col3
FROM DUAL
;
-- 1 rows inserted.
SELECT *
FROM tab_vw;
-- 1 11 1 21 22 23
-- 2 11 2 21 22 23