UPDATE tab1 t1 SET col_1 = (SELECT col_1 FROM tab2 t2 WHERE t1.id=t2.id); INSERT INTO table1 SELECT * FROM table2 WHERE ... INSERT INTO table1 (col_1, col_2) SELECT col_1, col_2 FROM table2 WHERE ...
Friday, December 21, 2018
Mass Update and Insert in Oracle
Oracle triggers
Oracle trigger can be used to modify data before update or insert in the same table.
Oracle update trigger:
Oracle insert trigger:
Oracle update trigger:
CREATE OR REPLACE TRIGGER update_time_col BEFORE UPDATE OF col_1, col_2 ON tab FOR EACH ROW BEGIN CASE WHEN UPDATING('col_1') THEN :new.time_col := SYSTIMESTAMP - INTERVAL '1' DAY; :new.col_1 := 'updated ' || :old.col_1; WHEN UPDATING('col_2') THEN :new.time_col := SYSTIMESTAMP + INTERVAL '1' DAY; :new.col_2 := 'updated ' || :old.col_2; END CASE; END; /
Oracle insert trigger:
CREATE OR REPLACE TRIGGER insert_time_col BEFORE INSERT ON tab FOR EACH ROW BEGIN :new.time_col := SYSTIMESTAMP + INTERVAL '10' DAY; :new.col_1 := 'insert ' || :new.col_1; :new.col_2 := 'insert ' || :new.col_2; END; /
Subscribe to:
Posts (Atom)