Instead of update trigger

Hi
I have a view, I like to create a update form for.
Someone have a sample how to use a "instead of update trigger" with a form?
I would like to have a report with a column link to the form, and the form use a "instead of update trigger" to update the row.
Best Regrads
Jesper Vels

Hi Jesper,
<p>I'm not sure I understand your problem correctly but I'll have a go nevertheless.</p>
<p>I think you can accomplish this with standard out of the box apex functionality. </p>
<p>You can create your report with a link to your data entry form which has auto DML functionality built in. I do not understand the need for an update trigger, based on what you have said. </p>
<p>I think this link will give you an idea how how to accomplish the functionality your looking for.</p>
<p>Otherwise In version 2.0 (the only version I have access to at the moment - though should be the same in 2.2). Create a new page of type form and specify "Form on a Table with Report" in the next stage of the wizard. Work through the rest of the wizard and see whether what is generated fits your purpose or can easily be adapted to suite your purposes. </p>
<p>Let me know how you get on.</p>
<p>Regards
Kris
</p>
Regards Kris

Similar Messages

  • ApEx 4.1.1: update record in a view with 'instead of update' trigger

    I created a form against a view. The view is complex enough which prevents direct updates. To incorporate the update logic I created an 'instead of update' trigger on the view. When I open up the form, do changes, and click 'Apply Changes' button I am getting the following exception
    ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.
    I understand that the standard 'Automatic Row Processing' process is trying to lock the record before updating using a cursor like
    select *
    from my_view
    for update
    and fails. Is it possible to bypass this locking while using the standard APEX processes?
    I think I can create a custom PL/SQL process which would execute the UPDATE statement (at least, it works in SQL*Plus), but I would like to know if I can use a standard ApEx functionality for this.

    Hello,
    Sorry for delay.
    I had found a feedback about trigger issue when restore SQL Database from a BACPAC file. Microsoft said the fixed  will be available in the next major release of DacFx.
    Feedback:
    SQL Azure fires a trigger when restoring from bacpac
    You can refer to the workarounds in the feedback. For example, if there is small amount of triggers on the database, you can try to remove the triggers and then recreate when restore from bacpac file.
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • Instead of Update Trigger error

    Hi all,
    I've been trying to solve this issue from past 4 to 5 days..I am unable to solve...Can someone please help....
    I hhave a requirement in which I need to update 4 tables from a single form...I created a view which will get the required fields along with the primary keys from all these 4 tables.
    Then I created a Instead of Update trigger as below
    CREATE OR REPLACE TRIGGER "HOMEPAGEVIEW_UPDATE"
    INSTEAD OF UPDATE ON cts_homepageview
    BEGIN
    DECLARE
    vID NUMBER;
    UPDATE cts_hardware_info
    SET STATUS_ID = :NEW.STATUS_ID,
    COMPUTER_NAME = :NEW.COMPUTER_NAME,
    OPERATINGSYSTEM_ID = :NEW.OPERATINGSYSTEM_ID
    where computer_id = :NEW.COMPUTER_ID;
    UPDATE cts_server_administrator
    SET PRIMARY_ADMIN_ID = :NEW.PRIMADMIN_ID,
    SECONDARY_ADMIN_ID = :NEW.SECONDADMIN_ID
    WHERE ID = :NEW.ID;
    UPDATE cts_location_info
    SET BUILDING_ROOM_RACK = :NEW.BUILDING_ROOM_RACK
    WHERE LOCATION_ID = :NEW.LOCATION_ID;
    UPDATE cts_maintenace_info
    SET MAINTENANCE_WINDOW = :NEW.MAINTENANCE_WINDOW
    WHERE MAINTENANCE_ID = :NEW.MAINTENANCE_ID;
    END;
    When I try to update a record, am gettting the following error
    ORA-20505: Error in DML: p_rowid=488, p_alt_rowid=COMPUTER_ID, p_rowid2=, p_alt_rowid2=. ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.
    Error Unable to process row of table CTS_HOMEPAGEVIEW.
    OK
    I have already posted this question on the forum, but dint get any replies so trying my luck again....Can someone plzzzzzz help...I searched on ths forum for similar requests...Found one post bt hte solution wasnt given...
    Thanks,
    Shravanthi
    Edited by: user0012 on Apr 29, 2009 9:54 AM

    Hi Varad and Andy,
    Thank you both for your responses first..I was soo tensed since no one replied to my previous post fr 5 days..
    Varad,
    With the change Andy told ('Begin & END'), I tried in SQL Workshop updated computer_name (of cts_hardware_info) data in the view..It updated the data. But from the form, it is still giving the same error.
    Andy,
    Here is my view.. All the table are associated with the cts_hardware_info using computer_id. And using this computer_id I have put all the data together.
    CREATE OR REPLACE FORCE VIEW "CTS_HOMEPAGEVIEW" ("COMPUTER_ID", "COMPUTER_NAME", "STATUS_ID", "DESCRIPTION", "OPERATINGSYSTEM_ID", "ID", "PRIMADMIN_ID", "PRIMARYADMIN_PHONE1", "SECONDADMIN_ID", "SECONDARYADMIN_PHONE1", "LOCATION_ID", "BUILDING_ROOM_RACK", "MAINTENANCE_ID", "MAINTENANCE_WINDOW") AS
    select g.computer_id,g.computer_name,g.status_id,cts_hardware_status.DESCRIPTION,g.operatingsystem_id,g.id,g.PrimAdmin_ID,g.PrimaryAdmin_Phone1,g.SecondAdmin_ID, g.SecondaryAdmin_PHONE1,g.location_id,g.BUILDING_ROOM_RACK,g.MAINTENANCE_ID,g.MAINTENANCE_WINDOW from
    (select e.computer_id,e.computer_name,e.status_id,e.operatingsystem_id,e.id,e.PrimAdmin_ID,e.PrimaryAdmin_Phone1,e.SecondAdmin_ID,e.SecondaryAdmin_PHONE1,
    e.location_id,e.BUILDING_ROOM_RACK,f.MAINTENANCE_ID,f.MAINTENANCE_WINDOW from
    (select c.computer_id,c.computer_name,c.status_id,c.operatingsystem_id,c.id,c.PrimAdmin_ID,c.PrimaryAdmin_Phone1,c.SecondAdmin_ID,c.SecondaryAdmin_PHONE1,
    d.location_id,d.BUILDING_ROOM_RACK from
    (select a.computer_id,a.computer_name,a.status_id,a.operatingsystem_id,b.id,b.PrimAdmin_ID,b.PrimaryAdmin_Phone1,b.SecondAdmin_ID,b.SecondaryAdmin_PHONE1 from
    (select cts_hardware_info.computer_id,cts_hardware_info.computer_name,cts_hardware_info.status_id,operatingsystem_id from cts_hardware_info) a
    left join
    (select cts_server_administrator.id,cts_server_administrator.computer_id,cts_administrator_contacts.ADMIN_id as PrimAdmin_ID,Phone1 as PrimaryAdmin_Phone1,
    (select ADMIN_id from cts_administrator_contacts where admin_id = CTS_Server_Administrator.Secondary_ADMIN_ID) as SecondAdmin_ID,
    (select Phone1 from cts_administrator_contacts where admin_id = CTS_Server_Administrator.Secondary_ADMIN_ID) as SecondaryAdmin_PHONE1
    from cts_server_administrator,cts_administrator_contacts where cts_administrator_contacts.admin_id = cts_server_administrator.PRIMARY_ADMIN_ID) b
    on a.computer_id = b.computer_id) c
    left join
    (select location_id,COMPUTER_ID,BUILDING_ROOM_RACK from cts_location_info) d
    on c.computer_id = d.computer_id) e
    left join
    (select MAINTENANCE_ID,COMPUTER_ID,MAINTENANCE_WINDOW from CTS_MAINTENACE_INFO) f
    on e.computer_id = f.computer_id) g left join cts_hardware_status on g.status_id = cts_hardware_status.STATUS_ID

  • Before update trigger on a view

    Hello,
    is not possible to write a before update or insert trigger based on a view?
    create or replace trigger trg_bef_upd_vwangajatiabsente
    before update on vw_angajati_absente
    referencing old as old new as new
    for each row
    begin
    if :old.motivabila='N' and :new.motivabila='D' then raise_application_error(-20433, 'Nu se poate modifica o absenta nemotivabila!');
    end;is it possible to solve these situations? :)
    Regards,

    Roger22 wrote:
    regarding to 2)
    in my trigger i must raise_application_error? if i don't raise then i need to issue update statements..... ?If you have an INSTEAD OF trigger that just has a body similar to the body you posted above, that would mean that update statements either
    - Raise an error
    - Do nothing (i.e. do not update any data in any table)
    That is a syntactically valid state-- Oracle will certainly allow you to have an INSTEAD OF UPDATE trigger that effectively throws away update statements. It's just that it would be rather rare that this would be the desired behavior. Presumably, if you're going through the effort of writing the trigger, you want certain update statements to succeed and, thus, to update data. If that is the case, your trigger would have to have UPDATE statements that update the proper row(s) in the proper base table(s).
    An INSTEAD OF UPDATE trigger is literally that. You are replacing, in its entirety, the update statement against the view with the code in your trigger. So your trigger would need to issue the base table updates that Oracle would have had there not been a trigger on the view.
    Justin

  • Error when a try to update a xmltype view thru a trigger instead of update

    <PERSON>
    <ID>4</ID>
    <FIRSTNAME>Frédéric</FIRSTNAME>
    <LASTNAME>Philippekin</LASTNAME>
    <SEX>M</SEX>
    <WEIGHT>75</WEIGHT>
    <HEIGHT>175</HEIGHT>
    </PERSON>
    CREATE OR REPLACE VIEW personne_oracle OF XMLType
    XMLSCHEMA "personOracle.xsd" ELEMENT "PERSON"
    WITH OBJECT ID (EXTRACT(sys_nc_rowinfo$, '/PERSON/ID').getNumberVal())
    AS SELECT XMLELEMENT("PERSON",
              XMLFOREST( Id,
    FirstName,
    LastName,
    Sex,
    Weight,
              Height)
    ) AS Valeur     
    FROM Person;
    CREATE OR REPLACE TRIGGER u_personne_oracle_tr
    INSTEAD OF UPDATE on personne_oracle
    BEGIN
    UPDATE Person SET
    Person.FirstName = extractvalue(:new.sys_nc_rowinfo$,'/PERSON/FIRSTNAME/text()'),
    Person.LastName = extractvalue(:new.sys_nc_rowinfo$,'/PERSON/LASTNAME/text()'),
    Person.Weight = extractvalue(:new.sys_nc_rowinfo$,'/PERSON/WEIGHT/text()'),
    Person.Height = extractvalue(:new.sys_nc_rowinfo$,'/PERSON/HEIGHT/text()')
    WHERE Person.Id = extractvalue(:new.sys_nc_rowinfo$,'/PERSON/ID');
    END;
    UPDATE personne_oracle x
    SET value(x) = updateXML(value(x), '/PERSON/FIRSTNAME/text()','Fred')
    WHERE extractValue(value(x), '/PERSON/ID') = 4;
    ORA-24358: OCIBindObject not invoked for a Object type or Reference
    please help me !

    What happens if you move the view to the remote db?
    and create a synonym for the view on the local?it doesn't work !
    >
    alternatively,
    what happens if you modify from person@oraclelink in
    the create or replace view personne_oracle?it doesn't work !
    The problem is the dblink ! Without it it's work !
    thx for your answer.

  • Instead of delete trigger rows deleted

    Hi All.
    Im using a few instead of triggers over a view. The view selects data from other tables and merges them together. This view essentially forms the parent of a few one2one relationships with other tables.
    However my application doesnt know its a view (im using hibernate orm framework) - so when I delete this object which is mapped to a view, I get an error saying that no records where deleted. Also, if i test in sqlplus, i get "0 rows deleted" in response to a delete - which of course is true, but i want it to say 1 or some number of my choice.
    How can i modify my "instead of delete" trigger so that the number for records deleted count returned to caller is 1, or some number i can define?
    Here is my current trigger...
    create or replace
    trigger product_view_delete_trigger
    instead of delete
    on product_view1
    for each row
    begin
    null;
    end;
    Thanks.

    In regards to why Im using a view - its discussed here...
    Crazy Union across 3 tables
    The view im using is not updatable - it uses a union. I use "instead of triggers" to trick my application into thinking its a real table which is insertable. And this works fine.
    Im having trouble tricking my application into think that the delete was successful, because the "instead of delete" trigger doesnt actually delete anything - which is what i wnat - but i want it to report back to the caller that a delete occurred.
    I want the SQL%ROWCOUNT to be set to 1 or whatever. Perhaps this is not hte variable, but im hoping there is some variable I can set which is used to report back to the client as to how many records were deleted.
    thx.

  • Update trigger error

    Hello,
    I have this issue where I'm getting the following error when executing an update in a view. Insert command appears to be OK. Any idea on what am I missing?
    ORA-01084: invalid argument in OCI call
    ORA-06512: at "APPS.XXRVM_TEMP_B_UPD_TR", line 2
    ORA-04088: error during execution of trigger 'APPS.XXRVM_TEMP_B_UPD_TR'
    -- sample update statement:
    update xxrvm_temp_b_v
    set text1 = 'ddd'
    where text1 = 'aaa'
    Thanks,
    Rownald
    ----- object definitions ----
    -- Located in TEST1 Dbase
    create table xxrvm_temp_b
    (text1 varchar2(30)
    ,text2 varchar2(30)
    -- Located in TEST2 Dbase
    -- view definition based on table at dblink
    create or replace force view xxrvm_temp_b_v
    (pri_key, text1, text2) as select rowid pri_key, text1, text2 from xxrvm_temp_b@test1;
    -- trigger definition for insert
    create or replace trigger xxrvm_temp_b_ins_tr
    instead of insert on xxrvm_temp_b_v referencing new as new old as old
    for each row
    begin
    insert into xxrvm_temp_b@test1 (text1, text2)
    values (:new.text1, :new.text2);
    end;
    -- trigger definition for update
    create or replace trigger xxrvm_temp_b_upd_tr
    instead of update on xxrvm_temp_b_v referencing new as new old as old
    for each row
    begin
    update xxrvm_temp_b@test1
    set text1 = :new.text1 ,text2 = :new.text2
    where rowid = :new.pri_key;
    end;

    Hello:
    Check if the update works if you re-write the on-update trigger as-- trigger definition for update
    create or replace trigger xxrvm_temp_b_upd_tr
    instead of update on xxrvm_temp_b_v referencing new as new old as old
    for each row
    begin
    update xxrvm_temp_b@test1
    set text1 = :new.text1 ,text2 = :new.text2
    where text1=:old_text1 and text2=:old_text2
    end;Varad

  • After Update Trigger issue

    Hello,
    I am having a problem with after update trigger. I have created an after update trigger in Oracle that would call a procedure to run an Oracle report. The problem is that when the report is run, the table is not updated yet. So the table passes old values to the report. Is there any way I can take care of this issue? How do I make sure the table is updated before running the report? I tried delaying the report by using dbms_job package. I didn't have any success with that. Probably I am doing something wrong. This is the code I used
    dbms_job.submit( job => l_job, what => 'SendPDFReport(:new.query_id,serviceid,:new.site_id);', next_date => sysdate+3/24*60 );
    Thanks
    Oracle database User

    It is working. I used the same code,but I was using parameters inside the single quote, so it was taking the parameter value as :new.query_id instead of 12345.
    I made changes
    from
    dbms_job.submit( job => l_job, what => 'SendPDF(:new.query_id,serviceid,:new.site_id);', next_date => sysdate);
    to
    dbms_job.submit( job => l_job, what => 'SendPDF('||:new.query_id||','||serviceid||','||:new.site_id||');', next_date => sysdate);
    Thanks for all your help.

  • Halting the update from a BEFORE UPDATE trigger

    Hello,
    I'm writing a trigger which is set to fire before update. One of the possible scenarios requires that the row being updated is not updated but instead deleted. Is it possible to send a DELETE query and then stop the update process so it doesn't spit out an error? I haven't tested this yet, but I'm quite sure it will give an error if it's trying to update a row which has just been deleted.
    Thanks,
    Pavel

    Hi,
    Personally, I don't like implement some business logic into trigger... so, why run an update whenever you need a delete ?
    I would modify the original code to delete in this case instead of update.
    My 2 cents,
    Nicolas.
    SQL> create table pavel (id number, txt varchar2(10));
    Table created.
    SQL> insert into pavel values (1, 'This one');
    1 row created.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace trigger pavel_trg
      2  before update on pavel
      3  for each row
      4  begin
      5  delete from pavel where id = :old.id;
      6* end;
    SQL> /
    Trigger created.
    SQL> update pavel set txt = 'Two';
    update pavel set txt = 'Two'
    ERROR at line 1:
    ORA-04091: table SCOTT.PAVEL is mutating, trigger/function may not see it
    ORA-06512: at "SCOTT.PAVEL_TRG", line 2
    ORA-04088: error during execution of trigger 'SCOTT.PAVEL_TRG'Message was edited by:
    N. Gasparotto

  • FRM-40735 POST- UPDATE trigger raised unhandled exception ORA- 01403

    FRM-40735 POST- UPDATE trigger raised unhandled exception ORA- 01403
    I am getting the above error when i am trying to change the Assignment Category field of
    an employee from Junior Staff to Senior Staff.
    Navigation People> Enter & Maintain> (B)Assignment.
    Kindly assist me to resolve this error.
    Plz note there is a promotion that is suppose to be given to some employees in our company as of
    01-APR-2010 so i had to open the closed payroll periods and do the changes. I managed to change for all
    the 9 employees but 1 employee's assignment is giving me an error as follows :
    FRM-40735 POST- UPDATE trigger raised unhandled exception ORA- 01403
    The error displays after i try to save the changes made to the Assignment Category from Junior Staff to Senior Staff.
    NB: i have also tried to switch off the custom code...but its giving me same error.
    Also the element links have been defined for employment category on the links window.
    please help!!
    Edited by: 594647 on Jul 20, 2010 10:26 PM

    Release 12.1.1.
    OS is Red Hat Ent Ed 4
    i am trying to change the employee assignment category from Junior to Senior. so when i am updating the assignment details on the assignment screen (Navigation is People >Enter & Maintain> Assignment) and trying to save, the system gives error on the status bar of the application as follows:
    FRM-40735 POST- UPDATE trigger raised unhandled exception ORA- 01403
    NB: Error is appearing on the Assignment screen.
    Please help!!
    Edited by: 594647 on Jul 21, 2010 2:48 PM

  • How can you create a simple insert or update trigger

    I am trying to create a simple insert or update trigger to timestamp an xml document when I load it into my XML DB repository but I always get an error trying to compile the trigger.
    "ORA-25003: cannot change NEW values for this column type in trigger"
    Here is my PL/SQL:
    CREATE OR REPLACE TRIGGER "PLCSYSADM"."PLCSYSLOG_TIMESTAMP"
    BEFORE
    INSERT
    OR UPDATE ON "PLCSYSADM"."PLCSYSLOG"
    FOR EACH ROW BEGIN
    :new.sys_nc_rowinfo$ := xmltype('<datestamp>' || SYSDATE || '</datestamp>');
    END;
    Does anyone have an example that works ?
    Thanks in advance
    Niels Montanana

    http://developer.apple.com/referencelibrary/HardwareDrivers/idxUSB-date.html

  • 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.

  • Update trigger is not working...

    Hi
    I am writing an update trigger.
    We have a two DB, one is application DB and other is reporting DB. We are writing trigger on Reporting DB. There is a job schedule for synchronizing the application data to reporting DB , this daly basis synchronization. So when the synchronization runs and if the FUNDING_RULE_TABLE is updated them my trigger gets called.
    CREATE OR REPLACE
    TRIGGER COMM_EXISTING_REP_TRIGGER AFTER UPDATE OF FR_IR_NAME ON FUNDING_RULE_TABLE
    DECLARE
    serialno INTEGER;
    CURSOR C_CES_REP IS
    Select distinct FR_IR_NAME,FR_IR_CODE from FUNDING_RULE_TABLE ;
    V_IR_NAME FUNDING_RULE_TABLE.FR_IR_NAME%TYPE;
    V_IR_CODE FUNDING_RULE_TABLE.FR_IR_CODE%TYPE;
    CURSOR C_CES_COMIT IS
    SELECT DISTINCT FR_IR_NAME1,FR_IR_CODE from COMM_EXSTS_COMIT_AGGR;
    IR_NAME VARCHAR2(20);
    IR_CODE VARCHAR2(10);
    BEGIN
    OPEN C_CES_REP;
    LOOP
    FETCH C_CES_REP INTO V_IR_NAME,V_IR_CODE;
    IF C_CES_REP%NOTFOUND THEN
    EXIT;
    END IF;
    OPEN C_CES_COMIT;
    LOOP
    FETCH C_CES_COMIT INTO IR_NAME,IR_CODE;
    IF(V_IR_CODE = IR_CODE AND V_IR_NAME = IR_NAME) THEN
    EXIT;
    ELSE
    update COMM_EXSTS_COMIT_AGGR set FR_IR_NAME1 = IR_NAME where FR_IR_CODE = IR_CODE;
    END IF;
    END LOOP;
    CLOSE C_CES_COMIT;
    END LOOP;
    CLOSE C_CES_REP;
    END COMM_EXISTING_REP_TRIGGER;
    The problem is:
    When the synchronization runs the trigger will gets called and the synchronization prc never stops because of the table locks.
    1)     why some tables are getting locks? (I think this is becuse some source is waiting for another to release-deadlock)
    2)     Is there any problem in trigger? (I think there is some problem is trigger)
    3)     When I comment below part then sync procedure works fine
    OPEN C_CES_COMIT;
    LOOP
    FETCH C_CES_COMIT INTO IR_NAME,IR_CODE;
    IF(V_IR_CODE = IR_CODE AND V_IR_NAME = IR_NAME) THEN
    EXIT;
    ELSE
    update COMM_EXSTS_COMIT_AGGR set FR_IR_NAME1 = IR_NAME where FR_IR_CODE = IR_CODE;
    END IF;
    END LOOP;
    CLOSE C_CES_COMIT;
    It menas that there is somr problem in trigger because i am reading and updation is performed on the same table "COMM_EXSTS_COMIT_AGGR ".
    Is this is the problem?
    waitting for ur rply...thx..
    Edited by: 931005 on Apr 30, 2012 2:38 AM

    Welcome to the forum!
    Whenever you post provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
    >
    1) why some tables are getting locks? (I think this is becuse some source is waiting for another to release-deadlock)
    >
    Because you have an UPDATE statement in your inner loop that may lock one or more rows that are updated.
    >
    2) Is there any problem in trigger? (I think there is some problem is trigger)
    >
    Many problems
    1. The outer query queries the same table that the update trigger is updating. So some rows may never get seen; rows inserted or updated by other sessions. This means the DISTINCT results may not be distinct at all.
    2. The cursors select into SCALAR variables so if either cursor returns more than one row the trigger will raise an exception.
    3. The nested cursor loops could be replaced by a simple update statement.
    4. The original issue of updating the same table queried by your cursor.
    Whatever it is you are trying to do - this isn't the way to do it.

  • After Update Trigger executes twice when single row is uptd thro proc

    We have the below trigger in our db. When a single record is updated using a procedure the trigger is executed twice and it inserts two records in other table.
    But when i issue an update statement using any sql client tool it is executing only once and inserts only one record in other table.
    Can any one please help me to find the reason?
    Trigger:*
    create or replace TRIGGER CX_HEADER_ESCL_T1 AFTER UPDATE OF STATUS ON CX_HEADER
    FOR EACH ROW
    DECLARE
    "b1-CTRIYJ" boolean := FALSE;
    BEGIN
    IF UPDATING('STATUS') AND(:NEW.status = 'SUCCESS') THEN
    "b1-CTRIYJ" := TRUE;
    END IF;
    IF "b1-CTRIYJ" = TRUE THEN
    INSERT
    INTO siebel.s_escl_req(req_id, created, bt_row_id, rule_id, tbl_name, created_by, group_id)
    VALUES('11111111', CURRENT_DATE, :NEW.row_id, '1-CTRIYJ', 'CX_HEADER', :NEW.last_upd_by, '1-2CU3');
    "b1-CTRIYJ" := FALSE;
    END IF;
    END;
    Procedure:
    CREATE OR REPLACE
    PROCEDURE CLOSE_BATCH
    (ChildRecordCount IN NUMBER, HeaderId IN VARCHAR2, CompletionStatus OUT VARCHAR2) AS
    CafeChildCount NUMBER;
    BEGIN
    select count(*) into CafeChildCount from SIEBEL.CX_CHILD where HEADER_ID=HeaderId;
    IF ChildRecordCount = CafeChildCount THEN
    update SIEBEL.CX_HEADER set STATUS ='SUCCESS', MODIFICATION_NUM = MODIFICATION_NUM+1 where HEADER_ID=HeaderId;
    CompletionStatus := 'SUCCESS';
    ELSE
    update SIEBEL.CX_CHILD set STATUS='FAILED' where HEADER_ID=HeaderId;
    update SIEBEL.CX_HEADER set STATUS='FAILED' where HEADER_ID=HeaderId;
    CompletionStatus := 'FAILED';
    END IF;
    commit;
    /*CompletionStatus := 'SUCCESS';*/
    EXCEPTION
    WHEN OTHERS THEN
    CompletionStatus := SQLCODE;
    rollback;
    END;

    Your problem seems not be related to the trigger restart issue I have already mentioned because you are using a AFTER UPDATE trigger and not a BEFORE UPDATE trigger:
    >
    BEFORE Triggers Fired Multiple Times
    If an UPDATE or DELETE statement detects a conflict with a concurrent UPDATE, then Oracle Database performs a transparent ROLLBACK to SAVEPOINT and restarts the update. This can occur many times before the statement completes successfully. Each time the statement is restarted, the BEFORE statement trigger is fired again. The rollback to savepoint does not undo changes to any package variables referenced in the trigger. Your package should include a counter variable to detect this situation.
    >
    If you are sure that you update a single row and that your trigger fires twice and if you can easiily reproduce the issue, I recommend that you contact Oracle Support and create a Service Request for your issue that could be an Oracle bug.

  • Update Trigger and COLUMNS_UPDATED()

    Let me rephrase my question:
    I want to know if there is a faster way (probably using bit operators) to see if COLUMNS_UPDATED() in an update trigger on a table with more than 8 columns contains any column other than 1 specific column I will refer
    to as 'columnToIgnore'. I don't care about which columns are included or if the value has actually changed, only that there are other columns present.
    Original question:
    I have inherited a Sql Server database + schema and corresponding application and I have been tasked with speeding up the batch update of users in the database. After running some profiling I discovered that the reason it was slow is because of an update
    trigger on the users table. I did some “cleaning up” of the trigger and now it runs faster but I still think it could be more efficient. The objective of the trigger is to write to an Audit table any time an update takes place and any column is updated (it
    does not actually matter if the value has changed or not) with the exception of 1 specific column. Now I have the following code in the trigger which I had refactored from something much uglier.
    DECLARE @ColumnsUpdated VARBINARY(100)
    SET @ColumnsUpdated = COLUMNS_UPDATED()
    DECLARE @onlyIgnoreColumnChanged int
    SET @onlyIgnoreColumnChanged = 1
    SET @onlyIgnoreColumnChanged = 1
    IF (EXISTS(SELECT 1
    FROM INFORMATION_SCHEMA.COLUMNS Field
    WHERE TABLE_NAME = 'users'
    AND sys.fn_IsBitSetInBitmask(@ColumnsUpdated, COLUMNPROPERTY(OBJECT_ID('dbo.users'), COLUMN_NAME, 'ColumnID')) <> 0
    AND column_name !='columnToIgnore')) BEGIN
    SET @onlyIgnoreColumnChanged = 0
    END
    Ideally I would change the code to disable the trigger and do the insert myself BUT the code is old Classic ASP ( ie. VBScript with ODBC database connections) so I am not going to change any of the calling code because that would cost too much time and probably
    create more problems than I am solving.
    My proposed fix which I am unsure of how to code in SQL:
    It seems to me that there should be a way to get the proper id or position for the column and see if the column was used in the COLUMNS_UPDATED().
    If it was not used then we can set @onlynieuwchanged to 0 for the remaining code (not shown)
    If it was used then remove the bit from the COLUMNS_UPDATED() and see if it is empty
    If its empty then then we can set @onlynieuwchanged to 1 for the remaining code (not shown)
    If it’s not empty then then we can set @onlynieuwchanged to 0 for the remaining code (not shown)
    My problem is I am not sure how to go about coding this logic in SQL. I would think it would be possible with BIT operators? It would seem this could be more efficient than what I have now as it would get rid of the select statement which could slow down
    a large batch update.
    Notes
    My table has 30+ some columns so more than 8 which is relevant when working with COLUMNS_UPDATED() from what I have read. It also means that testing each column with UPDATE() would probably be more inefficient than what I have now.
    The update is called from the front end code (VBScript) which currently times out although not as much as it used to with my latest change. I cannot alter the code to run async mode and show progress, it would be easier for me to update the trigger.
    Reason for audit - we only record the user id in an audit table. This is then used to force a sync to another system outside of our source control that is used for various other tasks (mailings, views, etc). Again, I do not want to change how this system
    works, I only want to speed up the existing trigger with minimal effort.
    Sql Server version 2012, database Schema is set to Sql server 2005 compatibility mode.
    Any help would be greatly appreciated. Thank you in advance!
    -Igor

    Thank you again everyone for your input. As I mentioned there is much out of my control. This is an active application worked on by many developers and has been pieced together over the past 10+ years. It is NOT well written, the database schema has MUCH
    to be desired, and the code is the classic definition of 'spaghetti' code and multiple platforms are used to access the data, and there are millions of lines of code. There is nothing I can do about all of this which is why I am ignoring much of the advice.
    Sure, if this was a new application or something that was well written and possible to do some modifications then I would BUT it's not. If I was given 1 year of dedicated time to fix everything... well, I would probably throw it all away and start from scratch.
    Here is what I finally came up with. It is probably not  much faster, if at all, but when I started this I thought there would be a simple solution that I did not see. I will probably leave my code the way it was but will include the following for reference.
    DECLARE @bit int, @field int, @char int, @comparisonField VARBINARY(100)
    -- the following segment recreates the value contained in COLUMNS_UPDATED() if only the field nieuw was altered and stores that value in field @comparisonField
    SET @field = (SELECT COLUMNPROPERTY(OBJECT_ID('dbo.users'), 'columnToIgnore', 'ColumnID')) -- geth the field id for column nieuw
    select @bit = (@field - 1 )% 8 + 1
    select @bit = power(2,@bit - 1)
    select @char = ((@field - 1) / 8) + 1
    -- select @field AS [Field number], @char AS [Char], @bit AS [Bit] -- debug code to check the bits that are tested.
    -- Recreate the binary value of just having the field present in the columns_updated
    SELECT @comparisonField = CONVERT(VARBINARY(100),'0x' + RIGHT('000000000000000000' + RIGHT(CONVERT(VARCHAR(30), CONVERT(varbinary(1), @bit), 1), 2), @char*2), 1)
    -- if the generated value in @comparisonField is the same as COLUMNS_UPDATED() then only nieuw was updated
    IF @comparisonField <> COLUMNS_UPDATED() BEGIN
    -- code to add to the tracking table
    END
    -Igor

Maybe you are looking for

  • Question on the A1038 Cinema Display

    A friend recently gave me his old display. I have a couple of questions about it - one of which I'm guessing I already know the answer to. First, I have the display hooked up to the DVI video on the G4. I did not hook up the USB cable. The power ligh

  • PLEASE HELP! TRIED RESETING STILL DOESN'T WORK!

    Heyy.. I tied reseting my ipod (pressing menu+middle button) but it still won't turn on at all.. i tied moving the hold button and i tried setting it on a flat surface and reseting it. Nothing worked. I am sure that it ran out of batteries but I don'

  • What am I doing wrong?  Enterprise Webservices arent working but...

    Hopefully this caught your attention.  I am having a problem with the Enterprise Services that are delivered in the different enhancement packs for ECC 6.0. My landscape is as follows: CE 7.1, PI 7.1, and ECC 6.0, and using the ESR (Service Registry

  • Re-sizing stills (including dpi settings)?

    I'm making a film with a lot of acquired stills at 300 dpi. I need to change the 300dpi to 72dpi. Can iPhoto do this? Or could you suggest a modest application (freeware or inexpensive) that will allow me to do this? I have Photoshop myself, but the

  • I have Photoshop Elements 11 and I keep getting error 6

    It happens like everyday and its really annoying. I bought a drawing tablet, that came with Elements, is there anyway I don't have to keep re-installing it?