Single Trigger for muliple tables

Hi All,
I have one requirement to create a trigger to populate a table (X) based on the any insert or update on few tables (A,B,C,D,E,F).
Do I need to create trigger for each table ??. any idea of using all tables in one trigger.

Hi,
this is not possible.
but you can use multiple trigger on single table
if you can use view, then you can use INSTEAD OF Trigger on view
for example
CREATE OR REPLACE VIEW manager_info AS
    SELECT e.ename, e.empno, d.dept_type, d.deptno, p.prj_level,
           p.projno
        FROM   Emp_tab e, Dept_tab d, Project_tab p
        WHERE  e.empno =  d.mgr_no
        AND    d.deptno = p.resp_dept;
CREATE OR REPLACE TRIGGER manager_info_insert
INSTEAD OF INSERT ON manager_info
REFERENCING NEW AS n                 -- new manager information
FOR EACH ROW
DECLARE
   rowcnt number;
BEGIN
   SELECT COUNT(*) INTO rowcnt FROM Emp_tab WHERE empno = :n.empno;
   IF rowcnt = 0  THEN
       INSERT INTO Emp_tab (empno,ename) VALUES (:n.empno, :n.ename);
   ELSE
      UPDATE Emp_tab SET Emp_tab.ename = :n.ename
         WHERE Emp_tab.empno = :n.empno;
   END IF;
   SELECT COUNT(*) INTO rowcnt FROM Dept_tab WHERE deptno = :n.deptno;
   IF rowcnt = 0 THEN
      INSERT INTO Dept_tab (deptno, dept_type)
         VALUES(:n.deptno, :n.dept_type);
   ELSE
      UPDATE Dept_tab SET Dept_tab.dept_type = :n.dept_type
         WHERE Dept_tab.deptno = :n.deptno;
   END IF;
   SELECT COUNT(*) INTO rowcnt FROM Project_tab
      WHERE Project_tab.projno = :n.projno;
   IF rowcnt = 0 THEN
      INSERT INTO Project_tab (projno, prj_level)
         VALUES(:n.projno, :n.prj_level);
   ELSE
      UPDATE Project_tab SET Project_tab.prj_level = :n.prj_level
         WHERE Project_tab.projno = :n.projno;
   END IF;
END;see more : http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_triggers.htm
Edited by: Mahir M. Quluzade on Oct 12, 2011 9:23 AM

Similar Messages

  • One trigger for Multiple tables

    Hi all,
    I want write a trigger for mutiple tables.
    For Example,
    In database schema,some user update one table.I want to capture what the table and capture old value and new value.
    the above example for all insert and delete also.
    Regards
    Fame

    Hi, Fame,
    Sorry, a trigger only works on one table, so you need a separate trigger on each separate table.
    All of those triggers can call a common procedure.
    If you'd like to give a more detailed description of what you want to do, using two or three tables, then someone can give you more detailed instructions on how to do it.
    Always say which version of Oracle you're using.

  • Creation of sequence and trigger for each table!!!!!!!1

    Hi
    I am new to trigger and Sequence field. In one of my database we have many tables with fields for specifing ID numbers. Iam planning to insert the ID field with help of a Sequence and trigger...that trigger fires by adding the sequence value from the dual table. Now the point is here we r having around *60* table with ID field. And i am planning use the above process for each table by creating sequences and trigger for each table.
    Will this affects the performance of database.
    Is there any other option other than the above process, I mean other than creating sequences and trigger for each table.
    PLzz help to resolve this issuee......
    Shiyas
    Edited by: user13170361 on Jun 7, 2010 12:37 AM

    Tiger, I didn't mind about your comment, but the point is try to use
    select NVL(max(a) + 1,1) into i from p1_temp;This line in your trigger code and see what is happening. The problem is with your trigger. You are using group by function and you will not get no_data_found !
    For more help, this is some modification of your code.
    SQL> create table p1_temp (a number(10) primary key, b number(10));
    Table created.
    SQL> create or replace trigger trg_p1_temp
      2  before insert on p1_temp for each row
      3  declare
      4  i number(10);
      5  begin
      6  begin
      7  select NVL(max(a) + 1,1) into i from p1_temp;
      8  exception
      9  when no_data_found then
    10  i := 1;
    11  end;
    12  :new.a := i;
    13  end;
    14  /
    Trigger created.
    SQL> insert into p1_temp(b) values (1);
    1 row created.
    SQL> insert into p1_temp(b) values (2);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from p1_temp;
             A          B
             1          1
             2          2
    SQL> Edited by: Saubhik on Jun 7, 2010 2:30 AM

  • HOW TO USE A SINGLE PERFORM FOR VARIOUS TABLES ?

    perform test TABLES t_header.
    select
           KONH~KNUMH
           konh~datab
           konh~datbi
           konp~kbetr
           konp~konwa
           konp~kpein
           konp~kmein
           KONP~KRECH
           FROM konh INNER JOIN konp
                  ON konpknumh = konhknumh
           into table iTABXXX
            "ANY TEMPERARY INTERNAL TABLE.
           for all entries in t_header
           where
                 konh~kschl = t_header-kschl
             AND konh~knumh = t_header-knumh.
    endform.
    how can I use above perform for various internal tables of DIFFERENT LINE TYPES but having the fields KSCHL & KNUMH.

    u can use single perform....
    just see this example......hope this is what u r expecting....
    tables : pa0001.
    parameters : p_pernr like pa0001-pernr.
    data : itab1 like pa0001 occurs 0 with header line.
    data : itab2 like pa0002 occurs 0 with header line.
    perform get_data tables itab1 itab2.
    if not itab1[] is initial.
    loop at itab1.
    write :/ itab1-pernr.
    endloop.
    endif.
    if not itab2[] is initial.
    loop at itab2.
    write :/ itab2-pernr.
    endloop.
    endif.
    *&      Form  get_data
          text
         -->P_ITAB1  text
         -->P_ITAB2  text
    form get_data  tables   itab1 structure pa0001
                            itab2 structure pa0002.
    select * from pa0001 into table itab1 where pernr = p_pernr and begda le sy-datum and endda ge sy-datum.
    select * from pa0002 into table itab2 where pernr = p_pernr and begda le sy-datum and endda ge sy-datum.
    endform.                    " get_data
    Regards
    vasu

  • Same trigger for several tables

    Is it possible?
    I want to modify the PK that is trying to be inserted with sys_guid() value. I have more or less 300 tables in the database so generating 300 triggers like
    create or replace trigger godtrigger
    before insert
    on X
    FOR EACH ROW BEGIN
    :NEW.id := sys_guid();
    END;
    does not appeal. I would like something like
    before insert
    on X,Y....Z
    Is this somehow achievable somehow?
    Thanks in advance

    But you can generate these triggers with dynamic SQL
    select table_name from all_tables where .....
    and change dynamically name of tables and triggers respectively.Could you work out the solution a little more? I haven't used "dynamic SQL" before.
    But ! The idea to use sys_guid() as PK is VERY BAD ! Why so? I need a quick way to generate the ids in a distributed db. I tought this would be better than sequences

  • How to set single parameters for two tables?

    SELECT GM.GRNNO,GM.GRNDATE,SUM(GS.APPROVED),SM.ISSUENO,SM.ISSUEDATE,GS.ITEMCODE,SUM(SS.ISSUEDQTY)
    FROM IMS_GRNM GM,IMS_GRNS GS, IMS_ISSUEM SM, IMS_ISSUES SS
    WHERE GM.GRNMSERIAL=GS.GRNSSERIAL
    AND SM.ISSUEMSERIAL=SS.ISSUESSERIAL
    AND GM.POSTED='T'
    AND SM.POSTED='T'
    AND GS.ITEMCODE=SS.ITEMCODE
    AND GS.ITEMCODE='01-01-02-019'
    AND *******
    GROUP BY GM.GRNNO,SM.ISSUENO,GM.GRNDATE,SM.ISSUEDATE,
    GS.ITEMCODE ORDER BY GM.GRNDATE,SM.ISSUEDATE;
    ******* here i have to select the data from both the tables between two parameters named :P_1 and :P_2.
    the date column in IMS_GRNM is named as GRNDATE.
    the date column in IMS_ISSUEM is named as ISSUEDATE.
    how to set such parameters???

    I think all you need is
    Where table1.column1 between :p1 and :p2
    and table2.column2 between :p1 and :p2

  • How to tcack the table update event in sap for all tables by use of single

    Hello,
         I want to store the list of all OM,HR tables in a file which are updated after perticular date. For that i tried TRIGGER but i can write only one trigger for one table, i want such a that  i have to write only one trigger which will be invoked affter update operation on every HR,OM tables and i store information in a file  regarding which rows are updated and external application can use it.
    Thanks in advance,     
    SANDIP

    hi all the log for the change of any thing will be available in the tables DBTABLOG..REPOSRC ....
    regards,
    venkat.

  • Can any one please send me an update trigger (pl/sql procedure) for ap tables(ap_suppliers,ap_supplier_site_all,and contacts)

    Please send an query for update trigger for those tables .
         1: ap_suppliers
         2: ap_supplier_sites_all
         3: ap_supplier_contacts.
    Thanks,
    Chaitanya.

    Hi,
    Actually ID and Data are different names in my API. Here I mentioned like that.
    Am using Oracle 10g version.
    Yes I am going to get the multiple values using this Ref Cursor. The same ref cursor is used in another API of my package.
    In this API, the user actually enters Application_id and data. API should insert/update the version_master table with the inputs. See application_id is the foriegn key for app_master table.
    The requirement is whenever they enters application_id and data, if application_id already present in the version_master table, then the data should be updated and we should get a status flag for this using Out variable(i.e. using ref cursor only we are showing the status). if the application_id is not present in the version_master table, new record should be inserted. The sequence will generate the version_id for version_master table.
    But the Merge statement is working fine for update and insert also. Problem is am unable to see the success or failure through ref cursor. I don't know how exactly I can use this.
    If data is NULL the operation should be failed. i.e. I should get Failure status here. But am not getting this.
    Please remove the comments here and then check. If I use the NVL2 function I was able to get the status flag, i.e. S or F.
    OPEN resultset_o FOR
    SELECT NVL2 (data, 'S', 'F')
    FROM version_master
    WHERE application_id = application_id_i;
    1.How the value of data being not null will determine Success of the api and how null failure
    2.If the above select statement goes in to exception when others how I will no the failure
    I have to achieve the above scenarios.
    Please advice me.

  • Trigger for more  than One table

    Hi,
    is it possible to create a trigger for more than one table?
    I need a trigger that fires when anyone of the users updates a special value in one of the DB tables.
    this value is in about 8 or 10 tables, or must i create a trigger for each table?
    thanx
    marcel

    You would wrap the functionality required into a packaged procedure and then have a trigger on each of these tables that simply call this packaged procedure.
    Yes, you would have one trigger per table.

  • Single invoice for multiple orders with different divisions

    Dear All,
    while I am trying to do single invoice for muliple orders with different divisons invoice is gettting splitted..In copy control vbrk routine I  tried with 003 and 007 etc..but result is same..what configuration need to be done for getting the single invoice
    Thanks In advance
    Regards
    CNRNAIR

    Hello
    single invoice for multiple orders with "different divisions" invoice is getting split
    FYI - Different Division means different Sales Area.
    So, sales doc (whether sales order, Delivery & Billing) is applicable to EXACTLY one sales area.
    Thus, combining docs with different sales area is practically impossible.
    Provided, you are using common division.
    Hope this assist you,
    Thanks & REgards
    JP

  • What is the maximum number of samples that can be acquired with a single trigger using PCI-6036E DAQ card?

    1. My PCI-6036E card has a FIFO of 1024 bytes in AI. Maximum how many samples can be acquired with single trigger for digitizing a waveform?
    2. PCI-6036E DAQ card has got a AO with 10ks/s update rate? Can I generate a pulsed output with the AO of this card? I need a pulse of, say, 5 V and 1 kHz frequency.

    Giri,
    1.The trigger is usually for enabling the acquisition. I mean, when it is logic zero, you acquire nothing; however, when it is logic one, you start acquiring your waveform,and you can acquire continuously without having to worry about how many samples, unless you want to set your program for doing so. You can acquire continuously by implementing buffer acquisition. Finally, the FIFO that is in the board will not affect the buffer acquisition.
    2.Yes, you can do that! You can generate your 5V signal with that specific frequency, and you should not have any problems, because the freq fits in the update rate.
    I hope this information is helpful.
    L Aguila
    Applications Engineer
    National Instruments

  • Is it possible raise a trigger for particular user

    hi,
    i have oracle user zil,i want to write trigger for this user..
    with out writting trigger for each table .
    for ex:
    i have 2 tables in this user
    1.emp
    2.audit_log
    suppose i m inserting values into emp table at the same time insert into audit_log with action as insert,like that suppose i m updating any row in emp then insert one row into audit_log with action as modify,
    my question is is it possible to write a trigger for the user zil,not for table emp
    so i can maintain audit_log..
    pls give me a solution
    regards
    singh

    It depends upon how you are connecting to the Oracle database, if you are connecting through CITRIX then it is difficult to identify the user or the other option for you is to have a field USER in each table and pass the user name form the front end.
    To captures the changes in the table EMP and insert into the AUDIT table you may need to write a trigger in the EMP table and before you INSERT into AUDIT check the user.
    Or why dont you use AUDITING provied by Oracle.
    Thanks

  • Single row editing for multiple tables in a single page

    Hi!
    I have split a table with many many columns into more tables with a lower number of columns. There is an ID column (sequence generated) that is Primary Key common for all tables. Obviously, the relationship between these tables is 1 to 1, so it’s not about having to build master-detail pages.
    What I need now is to edit all these tables in a single page: one single row from each table. The Automated Row Fetch & Automatic Row Processing (DML) processes used for the old table must be replaced by something else.
    Is there a way to use in a single page more pairs of such processes for more tables?
    I want to avoid manually writing processes with lot of PL/SQL code to handle row fetch & update.
    Keep in mind that the page will have an ID item that can be used to identify unique rows in all my tables.
    Thanks,
    Sorin

    I have split a table with many many columns into more tables with a lower number of columns
    IMHO that is a very bad idea. There is nothing wrong with having many columns in a table. If you would like to split them to better "categorize" them, just create views on the table and expose different subsets of the columns.
    I want to avoid manually writing processes with lot of PL/SQL code to handle row fetch & update.
    That is unavoidable given how you have designed the underlying tables.
    You could try creating a view that joins all the tables by the PK and creating a form based on that view. Then write a INSTEAD OF trigger on the view that "doles out" the DML on the view to each of the underlying tables.

  • How to insert entities for a role and retrofit single trigger from DB

    Hi,
    before Oracle Designer replacement I would like to clarify these 2 issues:
    - how to insert entities for a role?
    - how to retrofit just a single trigger from database?
    Could somebody give a step by step advice, how to do these 2 things? Thanks!

    > um.. i don't think you could use 'create table'
    inside a pl/sql procedure.
    You are wrong. You can create table inside a PL/SQL using execute immediate. But, this is not a good practise. I think you should reconsider the logic and then use such programming code. Please read the Oracle documentation regarding execute immediate.
    Regards.
    Satyaki De.

  • Trigger for logging changes(DML changes) for All tables in Schema

    Hi ,
    Is there a way to create a schema level trigger to audit the DML changes that affect all the tables.I need the output in my log table as
    1) the table name on which the DML occurred
    2) type of DML
    3) column names affected.
    I know this can be achieved through enabling AUDIT or by creating dynamically, triggers for each tables...
    Is there a way to create a single trigger to achieve this??

    It's not possible to create DML trigger on schema level
    I think the only way is to create the triggers dynamically for each table..
    Re: Schema level Database triggers by Kamran Agayev
    Edited by: jeneesh on Oct 12, 2012 6:39 PM

Maybe you are looking for