In the vast majority of cases, the only way to assign new values ββin a row to the variable% ROWTYPE is to explicitly assign each column. Something like
CREATE OR REPLACE TRIGGER some_trigger_name BEFORE INSERT OR UPDATE ON some_table FOR EACH ROW DECLARE l_row some_table%rowtype; BEGIN l_row.column1 := :NEW.column1; l_row.column2 := :NEW.column2; ... l_row.columnN := :NEW.columnN; procedure1( l_row ); procedure2( l_row ); procedure3( l_row ); END;
If your table is declared based on an object: NEW will be an object of this type. Therefore, if you have a table like
CREATE OR REPLACE TYPE obj_foo AS OBJECT ( column1 NUMBER, column2 NUMBER, ... columnN NUMBER ); CREATE TABLE foo OF obj_foo;
then you can declare procedures that take input parameters of type OBJ_FOO and call them directly from your trigger.
The suggestion in another thread about selecting a row from a table in the AFTER INSERT / UPDATE stream, unfortunately, usually does not work. This will usually result in the exclusion of the mutating table.
1 create table foo ( 2 col1 number, 3 col2 number 4* ) SQL> / Table created. SQL> create procedure foo_proc( p_foo in foo%rowtype ) 2 as 3 begin 4 dbms_output.put_line( 'In foo_proc' ); 5 end; 6 / Procedure created. SQL> create or replace trigger trg_foo 2 after insert or update on foo 3 for each row 4 declare 5 l_row foo%rowtype; 6 begin 7 select * 8 into l_row 9 from foo 10 where col1 = :new.col1; 11 foo_proc( l_row ); 12 end; 13 / Trigger created. SQL> insert into foo values( 1, 2 ); insert into foo values( 1, 2 ) * ERROR at line 1: ORA-04091: table SCOTT.FOO is mutating, trigger/function may not see it ORA-06512: at "SCOTT.TRG_FOO", line 4 ORA-04088: error during execution of trigger 'SCOTT.TRG_FOO'
Justin cave
source share