Trigger format to perform updates on another table

Hello there,
I am struggling to write a trigger that performs updates on table B when rows in my table A are updated , can anybody give me any general pointers in that direction?

Duplicate thread:
Will this trigger code work?
(this one is earlier, but at least the other one has some code).

Similar Messages

  • Updating from another table query

    I have tried a merge query and I think I am not doing this right or for what I want to accomplish, it will not work. Here is the problem:
    I have a lookup table
    create table lkp1(
    lkp_id number,
    lkp_name varchar2(100));
    and have a another table
    create table test(
    test_id number,
    lkp_id number,
    lkp_name varchar2(100));
    I am trying to pull in the lkp_id value from lkp1 table into the test table. I have the lkp_name field in the test table so that I can reference back to lkp1 so that I can pull in the lkp_id value. How would I go about doing this if the lkp_name field in test table has the value duplicated over many rows. For example 5 records in the test table might have the lkp_name of 'ORACLE', and its lkp_id from lkp1 table is 25. How do I populate the lkp_id in the test table with the value from the lkp1 table, without specfiying in the where clasue ...lkp_name = 'ORACLE'. There has to be a way. I tried the merge query, and WOW...I was really off.
    Please help!

    scott@ORA92> -- test data:
    scott@ORA92> select * from lkp1
      2  /
        LKP_ID LKP_NAME
             1 name1
             2 Oracle
    2 rows selected.
    scott@ORA92> select * from test
      2  /
       TEST_ID     LKP_ID LKP_NAME
            10            name1
            20            Oracle
            30            Oracle
    3 rows selected.
    scott@ORA92> -- update:
    scott@ORA92> update test set lkp_id =
      2  (select distinct lkp_id from lkp1 where lkp1.lkp_name = test.lkp_name)
      3  where exists (select lkp_id from lkp1 where lkp1.lkp_name = test.lkp_name)
      4  /
    3 rows updated.
    scott@ORA92> -- results:
    scott@ORA92> select * from test
      2  /
       TEST_ID     LKP_ID LKP_NAME
            10          1 name1
            20          2 Oracle
            30          2 Oracle
    3 rows selected.

  • File Format Mismatch while update into Internal table using RFC_REMOTE_FILE

    Hi All,
    I used RFC_REMOTE_FILE to communicate with the presentation server in Background Mode. I connected successfully and got output too.
    But my requirement is to update the .csv file into internal tables.
    With RFC_REMOTE_FILE i can get the data as single row. But I can't separate the fields and update into the corressponding table field.
    What is the solution for the above issue. Could anyone help me.
    For the above RFC Communication I followed the below link
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/9831750a-0801-0010-1d9e-f8c64efb2bd2&overridelayout=true

    Hi All,
    I used RFC_REMOTE_FILE to communicate with the presentation server in Background Mode. I connected successfully and got output too.
    But my requirement is to update the .csv file into internal tables.
    With RFC_REMOTE_FILE i can get the data as single row. But I can't separate the fields and update into the corressponding table field.
    What is the solution for the above issue. Could anyone help me.
    For the above RFC Communication I followed the below link
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/9831750a-0801-0010-1d9e-f8c64efb2bd2&overridelayout=true

  • Compression getting disabled when performing Update on partitioned tables

    Hi All,
    I am on Oracle Database 11g Enterprise Edition Release 11.2.0.3.0.
    My question is related to Oracle Compression.
    I have a sub-partitioned table enabled with Basic Compression. In enabled compressed state, I am updating few columns of this table(Normal Update command and Merge as well) but the end result shows increase in the table size and the compression is still in ENABLED state. Post that, if I compress the sub-partition explicitly the table comes back to its original size.
    Is it a bug? I read a white paper on 11g itself, that compression remains enabled in case of all DML operations, then why this behaviour?
    Thanks,
    Ishan

    Ishan,
    taking a look at http://docs.oracle.com/cd/E11882_01/server.112/e25494/tables.htm#CJAGFBFG It seems that the distinction between OLTP and basic compression is sometimes a little bit vague ("Operations that permit compression include: ..."), but I can also find the statement "Rows inserted without using direct-path insert and updated rows are uncompressed." So I would say it's not a bug but a limitation of the feature. Updates just don't mix well with compression.
    Martin

  • Update from another table

    I am new in oracle, can anybody help.
    I have table price1 and price2, and have same records, only the price is difference.
    price1 have field item_num, Group_num, unit_price, case_lot
    price2 have field item_num, Group_num, unit_price, case_lot
    I want to update unit_price and case_lot from table price1 to table price2 with pisible condition :
    1. all record (depend on user)
    2. certain group_num (variable, depent on user)
    3. certain item_num (variable, depent on user )
    Question :
    How to update table price2 using price1 in sql and with condition ?
    Thank's a lot.

    Assuming that field item_num is the primary key of each table:
    1. Update price1 maintbl
    Set (unit_price, case_lot) =
    (Select unit_price, case_lot from price2 where item_num = maintbl.item_num)
    Where Exists
    (Select 'x' from price2 where item_num = maintbl.item_num)
    2. Update price1 maintbl
    Set unit_price =
    (Select unit_price, case_lot from price2 where item_num = maintbl.item_num)
    Where
    group_num = whatever ....
    And Exists
    (Select 'x' from price2 where item_num = maintbl.item_num)
    3. Update price1 maintbl
    Set unit_price =
    (Select unit_price, case_lot from price2 where item_num = maintbl.item_num)
    Where
    item_num = whatever ....
    And Exists
    (Select unit_price from price2 where item_num = maintbl.item_num)
    There are other (perhaps better) ways of doing this, e.g. updating a view,
    but you have not given enough info about your tables. This is a fairly
    generic solution.

  • Updating column in table using forms...

    Well guyz i had my presentation of the application today..every thing went fine ....but still they wanna add more features i.e wanna gift this application to various PM working in the company on various project ....initailly i was told that u gotta create this application for just our project now they are using my work to give it to other PMsss :( and take all the credit with no ackowledgement for me n u people who helped me a lot in building this application.... ... well they want me to create an application where in they can modify certain columns......i.e over write the existing value present in a column with a new value....
    Now suppose i have col1,col2 in table paymast how should i proceed to create trigger for when i press the button the form gets updated for the particular employee number(i mean if enter the respective info for the particular emp as soon as i press the button the old values shud b replaced by new values..
    One method that i noe is use DB wizard to create the form n then enter the value for in respective fields for the column to be updated n then press the F6 ......i dont wanna use this function...
    i wanna update the application by pressing the button
    cheers :)
    Edited by: Suhail Faraaz on Nov 15, 2009 12:26 AM
    Edited by: Suhail Faraaz on Nov 15, 2009 12:29 AM
    Edited by: Suhail Faraaz on Nov 15, 2009 12:30 AM
    Edited by: Suhail Faraaz on Nov 15, 2009 2:05 AM

    hi
    Examples:
    SELECT TXNID INTO :TXNID  FROM SAF
          WHERE
          NEXT_ATTEMPT=(SELECT MIN(NEXT_ATTEMPT)
    FROM SAF
    WHERE STATUS!='A' AND NEXT_ATTEMPT<=SYSDATE AND ATTEMPTS<10)
    AND
          STATUS!='A' AND ATTEMPTS<10 AND
          ROWNUM=1 FOR UPDATE;
       //processing==success  
       UPDATE  SAF SET  ATTEMPTS=ATTEMPTS+1, NEXT_ATTEMPT=NEXT_ATTEMPT+(10/(24*60*60))
              WHERE TXNID=:TXNID;
            commit;
        else
            rollback;
    Create trigger trigg_name
      After update of C on A
    For each row
    Is
    declare
    Pragma Autonomous_transaction;
      New_val  varchar2(27);
    Begin
    New_val := :new.C;
    Dbms_output.put_line(New_val) ;  
                /* this outputs the new value when
           evoking an update statement on Table A (Column C)  */
    If updating then
    update A set D=:new.C where C=:old.C;
           /* After compiling the trigger and evoking
              an update statement on Table A (Column C)
              the D column still not being updated */
    Commit;
    End;
    update t1
    Set t1.C1 = (Select t2.c1
    From t2
    Where t1.c3 = t2.c3),
    t1.C2 = (Select t2.c2
    From t2
    Where t1.c3 = t2.c3)
    update t2
    Set t2.C1 = (Select t1.c1
    From t1
    Where t1.c3 = t2.c3),
    t2.C2 = (Select t1.c2
    From t1
    Where t1.c3 = t2.c3)Its Correct/Helpful Please mark it.Thanks.
    sarah

  • Conditional Extract (based on changes in another table)

    Hi guys,
    I have a question for nightly (incremental) loads. I want to select from certain tables even if there are updates to another table.
    For example, I nightly pull any changes (or new records) from table 1, 2, 3, 4, & 5.
    But, if table 1 has no changes, I still want to pull matching records from it if there are changes to any of the others.
    And similarly, I want to pull matching records from table 2 if there are changes to any of the others.
    Assume that the Last_update field is available in the source tables. (This is necessary for pulling key columns to match for updates.)
    Thanks.

    can you explain in details .?

  • Performance updating a extra huge table

    Hi guys, just an advice. I'm handling table with more than 300 millions rows, sometimes even 800 millions and so far I came up with some good solution but now I really need to be concerned about the performance. I got a table with:
    FlyID int, FlyNumber int, SettlDate datetime2, SettlPeriod double, Consumpt dec, Ixl dec, Aunit int
    300 millions rows. The settldate is a date , settperiod is an half hour ( so 48 period each day).
    The other table is:
    BMUnit int,  SettlDate datetime2, SettlPeriod double, Chargefact dec
    I'm going to join the two table on bmunit=bmunit, settdate=settdate, settperiod=settperiod and with an insert filling a new table
    Fingers crossed and I hope it wors within a reasonable time ( 3 hours...more?)
    The real concern is:
    I got another table with
    FlyID int, Company varchar, CompanyID int, FromDate datetime, ToDate datetime
    The logic should be something like this:
    Update table1 set 1companyid=dd.companyid , company=company
    where table1.flyid=company.flyid
    and settlementdate >= fromdate and settlementdate <= todate
    but just yesterday I tried something without date and the querr ran for more than seven hours and so I had to killed it. I'm wondering if there is a better way...all this stuff because I'm going to build several cube taking as source a big table. That's
    it's going to make the retrievement really fast, so far I cut pratically entire hours but now I need you this more element and before I start to write some code I'd like to hear some your advice..
    Thanks

    Tables that large are always a problem to do major maintenance.
    I would do your update in batches:
    DECLARE @cnt int;
    SET @cnt = 1;
    WHILE @cnt > 0
    BEGIN
    Update TOP 1000000 table1 set 1companyid=dd.companyid , company=company
    where table1.flyid=company.flyid
    and settlementdate >= fromdate and settlementdate <= todate
    SET @cnt=@@ROWCOUNT
    END

  • Updating a table, however I would like to save the old info in another tabl

    Dear all; I have a table called table_one,
    Which contains the following info
    carid            place
    Benz            New York
    BMW            LondonThis information is usually going to be updated in the near future, however, I would like a situation where before the information is updated, the old information will be saved in another table called table_two first. so for example, from table_one, lets say New York is being updated to Toronto, I would like
    Carid place
    Benz New York
    saved first in table_two before the update is done. How do I go about doing that. Thanks you

    it should have been
    CREATE OR REPLACE TRIGGER partinstance_before_update
       BEFORE UPDATE
       ON qc_shelf_life_part_instances
       FOR EACH ROW
    BEGIN
       INSERT INTO auditqcshelflifepartinstances
                   (a_part_number,
                    a_instance_number,
                    a_mfg_part_number,
                    a_description,
                    a_revision,
                    a_acount_number,
                    a_part_quantity,
                    a_measurement_unit,
                    a_mfg_date,
                    a_expiry,
                    a_location,
                    a_last_updated,
                    a_modified_by
            VALUES (:old.part_number,
                    :old.instance_number,
                    :old.mfg_part_number,
                    :old.description,
                    :old.revision,
                    :old.account_number,
                    :old.part_quantity,
                    :old.measurement_unit,
                    :old.mfg_date,
                    :old.expiry,
                    :old.LOCATION,
                    :old.last_updated,
                    :old.modified_by
    END;
    /

  • On submit perform an insert on one table and an update on aother table

    I am trying to perform and insert on the table one table (the wizard created my form the insert is going against the table that I created using the wizard) and on the form is on field that is also in another table. Therefore, I am trying to perform an update on one attribute of one table and a insert into another table. How do I do this in apex?

    If you have used wizard to create form, then you may see a process of type 'Automatic Row Processing (DML)' in your page which will perform INSERT/UPDATE/DELETE on your form table. Here you can see APEX performs INSERT only when REQUEST is in 'INSERT, CREATE, CREATE_AGAIN, CREATEAGAIN'
    So create one more PL/SQL page process which will execute at 'on Submit after validations' and write update process as follows
    begin
    -- pseudo table/columns
    update tbl_second
    set col1 = :p1_item
    where pk_col = :p1_pk_item;
    end;Make this process conditional so that it will perform UPDATE only when request value is in 'INSERT, CREATE, CREATE_AGAIN, CREATEAGAIN' ( i.e. only when you are inserting into your form table)
    Cheers,
    Hari
    p.s. I think you may also need to update the second table when some-one updates your form table.
    Edited by: Hari_639 on Oct 26, 2009 9:46 AM

  • How to Fire a trigger after an update of a table

    Hi
    I have a form that has one block and I am having the users
    entering some information in it then at end I am comiting the
    records. I would like after the records being comitted I want to
    fire a trigger to do some other things like populating another
    table. Could you please help me on this?
    What kind of trigger will I need? where I would I put the
    trigger?
    Thanks
    alpha

    Thank you much. Can I ask you another question please.
    I have a database trigger that need to be fired only when some
    columns on a tabke is being updated so I have the trigger like
    this
    create or replace trigger FRK_HZ_LOCATIONS_AUR
    after update of address1,address2,city,state
    ,postal_code,county,province,country,attribute20
    on hz_locations
    for each row
    DECLARE
    v_cust_account_id hz_cust_acct_sites_all.cust_account_id%type;
    v_cust_acct_site_id hz_cust_acct_sites_all.cust_acct_site_id%
    type;
    v_org_id hz_cust_acct_sites_all.org_id%type;
    -- cursor; all sites for this customer address
    cursor sc is
    select
    s.site_use_id site_use_id
    ,s.attribute15 frk_addr_number
    from
    ra_site_uses_all s
    where s.address_id = v_cust_acct_site_id
    and s.site_use_code in ('BILL_TO','SHIP_TO');
    rowcnt number;
    But the trigger is firing even thought they insert instead of
    update. Could you help please
    Thanks

  • INSTEAD OF trigger on view to update a table. error in 4.2apex tabular rpt

    I have created a view (LANDINGS_VIEW') that I am hoping to use to add/modify data over several tables. I am using INSTEAD OF trigger to update/insert into the underlying tables. I am receiving the error:
    •ORA-01858: a non-numeric character was found where a numeric was expected ORA-06512: at "SAFIS.LANDINGS_V_IO_UPD_TRG", line 4 ORA-04088: error during execution of trigger 'SAFIS.LANDINGS_V_IO_UPD_TRG' (Row 1)I am only setting PRICE = 300.
    any thoughts? Am I setting this up propertly? thanks for your help!!
    Karen
    The LANDING_VIEW is set up as follows:
    -- Start of DDL Script for View SAFIS.LANDINGS_VIEW
    -- Generated 03-May-2013 10:25:38 from [email protected]
    CREATE OR REPLACE VIEW landings_view (
       landing_seq,
       dealer_rpt_id,
       unit_measure,
       reported_quantity,
       landed_pounds,
       dollars,
       disposition_code,
       grade_code,
       species_itis,
       market_code,
       price,
       area_fished,
       sub_area_fished,
       lease_num,
       gear_code,
       de,
       ue,
       dc,
       uc,
       local_area_code,
       fins_attached,
       explanation,
       late_report,
       modified_data,
       nature_of_sale,
       hms_area_code,
       sale_price,
       deleted )
    AS
    select l.LANDING_SEQ,
           l.DEALER_RPT_ID,
           l.UNIT_MEASURE,
           l.REPORTED_QUANTITY,
           l.LANDED_POUNDS,
           l.DOLLARS,
           l.DISPOSITION_CODE,
           l.GRADE_CODE,
           l.SPECIES_ITIS,
           l.MARKET_CODE,
           l.PRICE,
           l.AREA_FISHED,
           l.SUB_AREA_FISHED,
           l.LEASE_NUM,
           l.GEAR_CODE,
           l.DE,
           l.UE,
           l.DC,
           l.UC,
           l.LOCAL_AREA_CODE,
           a.fins_attached,
           a.explanation,
           a.late_report,
           a.modified_data,
           a.nature_of_sale,
           a.hms_area_code,
           a.sale_price,
           a.deleted
      from landings l,
           landings_hms a
      where  l.dealer_rpt_id = v('P110_DEALER_RPT_ID') and
            l.dealer_rpt_id = a.dealer_rpt_id(+) and
            l.landing_seq = a.landing_seq(+)
    -- Triggers for LANDINGS_VIEW
    CREATE OR REPLACE TRIGGER landings_v_io_upd_trg
    INSTEAD OF
      UPDATE
    ON landings_view
    REFERENCING NEW AS NEW OLD AS OLD
    DECLARE
       v_first_day   date;
       BEGIN
    update landings set landing_seq = :old.landing_seq,
                              dealer_rpt_id = :old.dealer_rpt_id,
                              unit_measure = :new.unit_measure,
                              reported_quantity = :new.reported_quantity,  
                            --  landed_pounds = :new.landed_pounds,
                              dollars = :new.dollars,
                              disposition_code= :new.disposition_code, 
                              grade_code = :new.grade_code,
                              species_itis =  :new.species_itis,
                               market_code = :new.market_code,
                              price =  :new.price,
                              area_fished = :new.area_fished,
                              sub_area_fished = :new.sub_area_fished,
                           --   lease_num = :new.lease_num,
                              gear_code = :new.gear_code,
                              de = :new.de,
                              ue = :new.ue,
                              dc = :new.ue,
                              uc = :new.uc,
                              local_area_code =  :new.local_area_code ;     
        /*  update landings_hms  set dealer_rpt_id = :old.dealer_rpt_id,
                                 landing_seq = :old.landing_seq,
                                 fins_attached = :new.fins_attached,
                                 explanation = :new.explanation,
                                 late_report = :new.late_report,
                                 modified_data = :new.modified_data,
                                 nature_of_sale = :new.nature_of_sale,
                                 hms_area_code = :new.hms_area_code,
                                 sale_price = :new.sale_price,
                                 de = sysdate,
                                 ue = :new.ue,
                                 dc = :new.dc,
                                 uc = :new.uc ;                         
    end;
    -- End of DDL Script for Trigger SAFIS.LANDINGS_KEH_V_IO_TRG
    CREATE OR REPLACE TRIGGER landings_v_io_trg
    INSTEAD OF
      INSERT
    ON landings_view
    REFERENCING NEW AS NEW OLD AS OLD
    DECLARE
       v_first_day   date;
       BEGIN
    insert into landings_keh (landing_seq,
                              dealer_rpt_id,
                              unit_measure,
                              reported_quantity,
                              landed_pounds,
                              dollars,
                              disposition_code,
                              grade_code,
                              species_itis,
                              market_code,
                              price,
                              area_fished,
                              sub_area_fished,
                              lease_num,
                              gear_code,
                              de,
                              ue,
                              dc,
                              uc,
                              local_area_code)      
       values ( landings_seq.NEXTVAL,
                :new.dealer_rpt_id,
                :new.unit_measure,
                :new.reported_quantity,
                :new.landed_pounds,
                :new.dollars,
                :new.disposition_code,
                :new.grade_code,
                :new.species_itis,
                :new.market_code,
                :new.price,
                :new.area_fished,
                :new.sub_area_fished,
                :new.lease_num,
                :new.gear_code,
                sysdate,
                :new.ue,
                :new.dc,
                :new.uc,
                :new.local_area_code)  ;
       insert into landings_hms (dealer_rpt_id,
                                 landing_seq,
                                 fins_attached,
                                 explanation,
                                 late_report,
                                 modified_data,
                                 nature_of_sale,
                                 hms_area_code,
                                 sale_price,
                                 de,
                                 ue,
                                 dc,
                                 uc,
                                 deleted)
           values (:new.dealer_rpt_id,
                   landings_seq.CURRVAL,
                   :new.fins_attached,
                   :new.explanation,
                   :new.late_report,
                   :new.modified_data,
                   :new.nature_of_sale,
                   :new.hms_area_code,
                   :new.sale_price,
                   sysdate,
                   :new.ue,
                   :new.dc,
                   :new.uc,
                   :new.deleted);
    end;
    -- End of DDL Script for Trigger SAFIS.LANDINGS_KEH_V_IO_TRG
    -- End of DDL Script for View SAFIS.LANDINGS_VIEWbtw, I have succefully run the following update in sqlplus.
    update landings set landing_seq = 8604583,
    dealer_rpt_id = 2660038,
    unit_measure = 'LB',
    reported_quantity = 3,
    -- landed_pounds = :new.landed_pounds,
    dollars = 900,
    disposition_code= '001',
    grade_code = '10',
    species_itis = '160200',
    market_code = 'UN',
    price = 30,
    area_fished = null,
    sub_area_fished =null,
    -- lease_num = :new.lease_num,
    gear_code = '050',
    de = sysdate,
    ue = 'keh',
    dc = null,
    uc = 'keh',
    local_area_code = null
    where landing_seq = 8604583; I am using apex 4.2
    Edited by: KarenH on May 3, 2013 10:29 AM
    Edited by: KarenH on May 3, 2013 10:31 AM
    Edited by: KarenH on May 3, 2013 11:04 AM
    Edited by: KarenH on May 3, 2013 4:09 PM

    could it be so simple?
    when I created the tabular form on my view, LANDINGS_VIEW, the APPLYmru was automatically generated, referencing the view name LANDINGS_VIEW. I modified that to indicate the table name (LANDINGS). I am not certain why that would work, but it seems to so far.
    this post was helpful: Re: instead of trigger on view
    I am now testing to make certain both the underlying tables can be updated, LANDINGS and LANDINGS_HMS

  • Need help in SQL Query: Update a row in a table & insert the same row into another table

    I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
    Thanks in Advance.

    Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
    SQL> var v_id number
    update tableA  
    set colB='ABC' 
    where colC='XYZ' 
    returning id into :v_id;
    insert into table A_History (ID, colA, colB, ColC)  
    select id, ColA, ColB, ColC  
    from tableA  
    where id = :v_id;   

  • Update on a Table is Slow After a New Trigger is Applied on Table.

    Hi All,
    Here is the situation:
    1. Table A - we have INSURANCE Records. If we have to cancel Insurance for an agent we have to update cancellation_date &
    INS_Flag sysdate & 'N' respectively. It is having thousands of records.
    - > Every time we update a record with cancellation_date & INS_Flag there are two other tables which are updating using
    trigger.
    - > For each record updated in Table A we have to terminate the existing contract in Table B and set the INS_flag to N in third
    Table C.
    2. Table B - It is the primary table for all the INSURANCE contracts. so we have to terminate existing contracts for those agent who are
    having cancellation_date & INS_Flag in table A.
    3. Table C - It is having all the basic contracts with a flag for INSURANCE Contracts. If a agent is having a flag as Y in this table must have a
    INSURANCE contract in Table B.
    Now We are having a simple after update trigger on TABLE A which will update table B & Table C accordingly for each row.
    We are having Table A so that we can synchronize Oracle Apps Database & Oracle Database for deverlopers.
    Before trigger - Update on table A was fast but after implementing the trigger it takes 4-5 mins. for 10 records update in table A.
    There are several indexes on Table A as well( including several functional indexes ).
    Oracle Database :
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE 10.2.0.3.0 Production
    TNS for Solaris: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Please help me How can I make the update faster.
    If it is required I will post the trigger code as well.
    Many thanks in advance.
    Edited by: Kamal Sharma on Jun 23, 2010 4:10 PM

    Here Table A = TB_CMA063_NETONE_STAGE_DATA
    Table B = TB_30.REAL_ESTATE_AGENT_NUM
    Table C = TB_CMA009_SUPRA_RE_AGNT_CONT
    CREATE OR REPLACE TRIGGER CMADBA.TR_CMA003_ALTERINS_ON_FLG_UPD
    AFTER UPDATE
    ON CMADBA.TB_CMA063_NETONE_STAGE_DATA
    REFERENCING NEW AS New OLD AS Old
    FOR EACH ROW
    DECLARE
        g_exception_id      TB_CMA089_CMA_APPS_EXCEPTION.EXCEPTION_ID%Type;
        v_msg               varchar2(200);
        v_status            varchar2(10);
        l_cmn               NUMBER;
        l_board_cmn         NUMBER;
    BEGIN
        SELECT CUSTOMER_MASTER_NUM INTO l_board_cmn FROM TB_CMA005_CUSTOMER_MASTER 
        WHERE IS_REAL_ESTATE_BOARD_FLG='Y'
        AND UPPER(RE_NETONE_NAM) = UPPER(:new.IR_INSTALL_SITE_NAM);
        IF :new.IR_INSURANCE_FLG = 'N' THEN
            BEGIN
            -- CANCEL Table 30 record for this agent
            UPDATE TB_CMA030_RE_AGENT_INS_PR_BIL TB_30
               SET TB_30.cancellation_dt = SYSDATE,
                   TB_30.RECORD_UPDATE_FLG = 'Y'
             WHERE TB_30.REAL_ESTATE_AGENT_NUM = :new.IR_AGENT_ID_NAM
               AND CANCELLATION_DT IS NULL          
               AND CUSTOMER_MASTER_NUM = l_board_cmn;
                -- UPDATE TABLE 9 RUF to Y so that Contract API would process this agent in next run
                UPDATE TB_CMA009_SUPRA_RE_AGNT_CONT
                SET RECORD_UPDATE_FLG='Y'
                WHERE REAL_ESTATE_AGENT_NUM = :new.IR_AGENT_ID_NAM
                    AND CANCELLATION_DT IS NULL
                    AND CUSTOMER_MASTER_NUM = l_board_cmn;
            END;          
        ELSIF :new.IR_INSURANCE_FLG = 'Y' THEN
            BEGIN
                INSERT INTO TB_CMA030_RE_AGENT_INS_PR_BIL
                    (BILL_FREQ_UNIT_CD,CUSTOMER_MASTER_NUM,SERIAL_NUM,REAL_ESTATE_AGENT_NUM,REAL_ESTATE_BOARD_NUM,
                    PRODUCT_NAM,  SERVICE_TYPE_NAM,  LEASE_TYPE_NAM,  CONT_START_DT, RE_AGENT_CUSTOMER_MASTER_NUM,
                    RE_AGENT_CONT_START_DT, INS_BILL_FREQ_UNIT_CD,
                    CONT_END_DT, RECORD_UPDATE_FLG, INS_AGENT_CONT_START_DT)
                SELECT DISTINCT 'AN', TB009.CUSTOMER_MASTER_NUM, TB009.SERIAL_NUM,
                    TB009.REAL_ESTATE_AGENT_NUM, TB009.REAL_ESTATE_BOARD_NUM, TB009.PRODUCT_NAM, 'INS',
                    TB009.LEASE_TYPE_NAM, TB009.CONT_START_DT, TB009.RE_AGENT_CUSTOMER_MASTER_NUM, TB009.RE_AGENT_CONT_START_DT,
                    TB009.BILL_FREQ_UNIT_CD, TB009.CONT_END_DT, 'Y', TRUNC(SYSDATE)
                FROM TB_CMA009_SUPRA_RE_AGNT_CONT TB009
                WHERE TB009.CUSTOMER_MASTER_NUM = l_board_cmn
                AND TB009.CANCELLATION_DT       IS NULL
                AND TB009.IS_TRAINING_KEY_FLG   = 'N'
                AND TB009.REAL_ESTATE_AGENT_NUM =  :new.IR_AGENT_ID_NAM
                AND TB009.product_nam           IN ('AKY','DKY')
               and not exists
                  (select 'x'
                     from tb_cma030_re_agent_ins_pr_bil tb030
                    where tb030.customer_master_num   = tb009.customer_master_num
                      and tb030.real_estate_agent_num = tb009.real_estate_agent_num
                      and tb030.serial_num            = tb009.serial_num
                      and tb030.ins_bill_freq_unit_cd = tb009.bill_freq_unit_cd
                      and tb030.product_nam           = tb009.product_nam);
                -- UPDATE TABLE 9 RUF to Y so that Contract API would process this agent in next run
                UPDATE TB_CMA009_SUPRA_RE_AGNT_CONT
                SET RECORD_UPDATE_FLG='Y', AGENT_KEY_INS_FLG='Y'
                WHERE REAL_ESTATE_AGENT_NUM = :new.IR_AGENT_ID_NAM
                    AND CANCELLATION_DT IS NULL
                    AND CUSTOMER_MASTER_NUM = l_board_cmn;
            END;
        END IF;   
    EXCEPTION
        WHEN OTHERS THEN          
            pc_cma024_batchjob.sp_cma025_log_err(l_board_cmn
                                                ,'UPDATE_TB63_TRIGGER'
                                                ,'TRIGGER-TR_CMA003_ALTERINS_ON_FLG_UPD'
                                                ,sqlcode
                                                ,sqlerrm,
                                                'An error occurred when Table 63 trigger tried to cancel/create Table 30 record for Agent ' || :new.IR_AGENT_ID_NAM);
    End;
    /

  • How to update one table based on another table ??

    Hello Friends:
    I am trying to run the following query in oracle but it won't run.
    UPDATE BOYS
    SET
    BOYS.AGE = GIRLS.AGE
    FROM GIRLS
    WHERE
    BOYS.FIRSTNAME = GIRLS.FIRSTNAME AND
    BOYS.LASTNAME = GIRLS.LASTNAME;
    This query runs fine in sql server but in oracle its saying can't find "SET". PLease tell me what is the correct syntax in oracle to update one table based on another table.
    thanks

    See if this helps.
    If you wrote an SQL statement:
    update boys set age = 10;
    Every row in the boys table will get updated with an age of 10. But if you wrote:
    update boys set age = 10
    where firstname = 'Joe';
    Then only the rows where the firstname is Joe would be updated with an age of 10.
    Now replace the 10 in the above statements with (select g.age from girls g where g.firstname = b.firstname and g.lastname = b.lastname) and replace where firstname = 'Joe' in the second statement with where exists (select null from girls g where g.firstname = b.firstname and g.lastname = b.lastname). The same concepts apply whether 10 is an actual value or a query and whether you have a where clause with the update statement to limit rows being updated.
    About the select null question regarding the outer where clause:
    Since the query is checking to see if the row in the girls table exists in the boys table what the column is in this select statement doesn't matter, this column isn't being used anywhere. In this case Todd chose to use null. He could have also used a column name from the table or a lot of times you'll see the literal value 1 used here.

Maybe you are looking for