How to get table fields from which was called a trigger with Oracle 10g? -


i want calculate average of values ​​in column of table (pra_coeff) (rapport_visite) field (pra_num) given, when add or change row of it. want save value in table (practitioner) row pra_num worth pra_num given above.

create table "rapport_visite"  ( "rap_num" number (10,0),  "pra_num" number (10,0),  "pra_coeff" number (10,0),  )   create table "praticien"  ( "pra_num" number (10,0),  "pra_coefconf" number  )  

the trigger called when adding or modification rapport_visite table. tried this, can not retrieve row affected trigger, , pra_num, need read.

create or replace trigger udpate_prat_coefconf   after insert or update on rapport_visite    declare   somme number;   nb number;   moyenne number;   rapport number;   pra_id number;  begin    /*select max(rap_num) rapport rapport_visite; // not want need in case modify row... */   select pra_num pra_id rapport_visite rap_num=rapport;   select sum(pra_coeff) somme rapport_visite pra_num=pra_id;   select count(*) nb rapport_visite pra_num=pra_id;    if (nb != 0)     moyenne := somme/nb;     moyenne := trunc (moyenne,1);     update praticien set pra_coefconf=moyenne pra_num=pra_id;   end if;  end; 

here 2 limits triggers have:

  1. when invoked affected records, don't know have changed

  2. when invoked individual records (for each row), limited access modified table

to address limitation, starting oracle 11g, can use compound trigger:

create or replace trigger <trigger-name> <trigger-action> on <table-name> compound trigger  -- global declaration. g_global_variable varchar2(10); -- block 1 before statement begin null; -- here. end before statement; -- block 2 before each row begin null; -- here. end before each row; -- block 3 after each row begin null; -- here. end after each row; -- block 4 after statement begin null; -- here. end after statement;  end <trigger-name>; 

and looks need. in block 1, initialize variables, in block 2 or 3 collect changes individual rows, in block 4 use information create rest of business logic.


if limited 10g, can emulate compound trigger using package variables. solution limited, because package variables global session. if withing session have 2 similar operations, results merged.

here solution

  1. you have 3 separate triggers, represent block 1, (2 or 3), , 4 trigger above.

  2. you have package variable g_global_variable (from above)

3 actions:

1. in trigger block 1 initiate g_global_variable  2. in trigger block 2 or 3, populate actual values 3. in trigger block 4, create logic 

ofcourse, g_global_variable not alone, record or collection.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -