Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ORA-04091: table SCMA.TBL1 is mutating, trigger/function may not see it
- ORA-06512: at "SCMA.TRG_T1_TBL1_COL1", line 4
- ORA-04088: error during execution of trigger 'SCMA.TRG_T1_TBL1_COL1'
- create or replace TRIGGER TRG_T1_TBL1_COL1
- BEFORE INSERT OR UPDATE OF t1_appnt_evnt_id ON TBL1
- FOR EACH ROW
- WHEN (NEW.t1_prnt_t1_pk is not null)
- DECLARE
- v_reassign_count number(20);
- BEGIN
- select count(t1_pk) INTO v_reassign_count from TBL1
- where t1_appnt_evnt_id=:new.t1_appnt_evnt_id and t1_prnt_t1_pk is not null;
- IF (v_reassign_count > 0) THEN
- RAISE_APPLICATION_ERROR(-20013, 'Multiple reassignments not allowed');
- END IF;
- END;
- dev> create or replace function f( a number, b number ) return number deterministic as
- 2 begin
- 3 if a is null then return 0-b; else return a; end if;
- 4 end;
- CREATE UNIQUE INDEX my_index ON my_table
- ( t1_appnt_event, f( t1_prnt_t1_pk, primary_key_column) );
- CREATE UNIQUE INDEX cappec_ccip_uniq_idx
- ON tbl1 (t1_appnt_event,
- CASE WHEN t1_prnt_t1_pk IS NOT NULL THEN 1 ELSE t1_pk END);
- CREATE OR REPLACE PACKAGE trigger_pkg;
- PROCEDURE before_stmt_trigger;
- PROCEDURE for_each_row_trigger(row IN ROWID);
- PROCEDURE after_stmt_trigger;
- END trigger_pkg;
- CREATE OR REPLACE PACKAGE BODY trigger_pkg AS
- TYPE rowid_tbl IS TABLE OF(ROWID);
- modified_rows rowid_tbl;
- PROCEDURE before_stmt_trigger IS
- BEGIN
- modified_rows := rowid_tbl();
- END before_each_stmt_trigger;
- PROCEDURE for_each_row_trigger(row IN ROWID) IS
- BEGIN
- modified_rows(modified_rows.COUNT) = row;
- END for_each_row_trigger;
- PROCEDURE after_stmt_trigger IS
- BEGIN
- FOR i IN 1 .. modified_rows.COUNT LOOP
- SELECT ... INTO ... FROM the_table WHERE rowid = modified_rows(i);
- -- do whatever you want to
- END LOOP;
- END after_each_stmt_trigger;
- END trigger_pkg;
- CREATE OR REPLACE TRIGGER before_stmt_trigger BEFORE INSERT OR UPDATE ON mytable AS
- BEGIN
- trigger_pkg.before_stmt_trigger;
- END;
- CREATE OR REPLACE TRIGGER after_stmt_trigger AFTER INSERT OR UPDATE ON mytable AS
- BEGIN
- trigger_pkg.after_stmt_trigger;
- END;
- CREATE OR REPLACE TRIGGER for_each_row_trigger
- BEFORE INSERT OR UPDATE ON mytable
- WHEN (new.mycolumn IS NOT NULL) AS
- BEGIN
- trigger_pkg.for_each_row_trigger(:new.rowid);
- END;
- Session 1> update tbl1
- set t1_appnt_evnt_id=123
- where t1_prnt_t1_pk =456;
- /* OK, trigger sees count of 0 */
- Session 2> update tbl1
- set t1_appnt_evnt_id=123
- where t1_prnt_t1_pk =789;
- /* OK, trigger sees count of 0 because
- session 1 hasn't committed yet */
- Session 1> commit;
- Session 2> commit;
- select appe_id
- into v_app_id
- from parent_table
- where appe_id = :new.t1_appnt_evnt_id
- for update;
Add Comment
Please, Sign In to add comment