How to make before delete trigger

Hi all
I want make before delete trigger
I have 2 tables hr_api_transactions and new_table
when I delete records from hr_api_transations table
then that deleted record should be stored/insert in new_table table
for that purpose I need before delete trigger
How can I make It?

Hi
I have written following code but it gives an error
CREATE OR REPLACE TRIGGER before_delete_trigger
    BEFORE DELETE
        ON HR_API_TRANSACTIONS
        FOR EACH ROW
    DECLARE
    BEGIN
        delete from new_table where new_table.name = OLD.hr_api_transactions.api_addtnl_info;
    END;
TRIGGER BEFORE_DELETE_TRIGGER compiled
Errors: check compiler logafter show errors it shows
4/54 PL/SQL: ORA-00904: "OLD"."HR_API_TRANSACTIONS"."API_ADDTNL_INFO": invalid identifier
4/9 PL/SQL: SQL Statement ignoredhere hr_api_transaction is table which contain API_ADDTNL_INFO column
and name column of new_table and API_ADDTNL_INFO column of
HR_API_TRANSACTIONS table are same

Similar Messages

  • Get Current SQL in Before delete trigger

    Hi,
    I have created a before delete trigger to track which records are deleted from a table I need to know what statements fires the trigger. can someone please describe how I can retrieve the current SQL.
    using sys_context('userenv','CURRENT_SQL') returns null for CURRENT SQL
    Note:
    For me the easier is to enable auditing and audit delete on the table however at the moment I cant get a downtime from the business to bounce the database to enable auditing.
    CREATE OR REPLACE TRIGGER before_delete BEFORE DELETE
    ON AUDIT_TEST_TAB
    FOR EACH ROW
    DECLARE
    v_username varchar2(50);
    v_stmt varchar2(255);
    v_client_info varchar2(200);
    v_os_user varchar2(50);
    v_machine varchar2(50);
    v_program varchar2(50);
    v_module varchar2(50);
    v_auth_type varchar2(200);
    v_ip_addr varchar2(200);
    v_sql_statement VARCHAR2(4000);
    BEGIN
    SELECT sys_context ('USERENV', 'CURRENT_SQL')
    INTO v_sql_statement
    FROM dual;
    -----------insert into logging table statment ----
    end;

    A few comments.
    Lets assume you run a delete statement that deletes 550 rows from your table. If your trigger is working then the very same statement would be stored 550 times. I think an BEFORE or better an AFTER delete STATEMENT level trigger would be the better choice. Why AFTER? Because if the delete operation fails, for example because of existing child records, then everything is rolled back anyway to the implicit savepoint just before the delete.
    So to store the SQL statement the correct trigger would be an AFTER STATEMENT DELETE trigger.
    Now what to store: You want the sql statement. You could try to find the cursor/currently running SQL. It might be tricky to separate that from the SQLs that you run to find this out.
    It could even be possible to simply save all commands that are in your PGA/Cached cursor area. First find out yur session, then store the SQL_text (first 60 chars) for all the cursors in this session by using v$open_cursor or the first 1000 chars by using v$sql.
    Here are a few views that might be helpful. v$session , v$open_cursor, v$sql, v$sqltext, v$sql_bind_data, v$sql_bind_capture, dba_hist_sqltext

  • Before delete trigger and foreign key relationship

    Hi,
    I am analysing one database for migration. On one parent table there is before delete trigger , to delete records from child. Also there is foreign key relationship on child table for this parent table.
    When I am deleting a row from parent, message gets displayed as "there are child records found."
    I would like to know, if there is foreign key relatioship then delete trigger on parent does't work, what is exactly happening?

    Could you post that trigger code and the Oracle version as well?
    With basic assumptions, I can't reproduce what you have stated here.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> create table parent (id number primary key);
    Table created.
    SQL> create table child (id number);
    Table created.
    SQL> alter table child add constraint fk_parent foreign key (id) references parent;
    Table altered.
    SQL> create or replace trigger bdr_parent
      2  before delete on parent
      3  for each row
      4  begin
      5  delete from child where id = :old.id;
      6  end;
      7  /
    Trigger created.
    SQL> insert into parent (id) values (1);
    1 row created.
    SQL> insert into child (id) values (1);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> delete from parent where id = 1;
    1 row deleted.
    SQL> select * from parent;
    no rows selected
    SQL> select * from child;
    no rows selected
    SQL> rollback;
    Rollback complete.
    SQL> alter table child drop constraint fk_parent;
    Table altered.
    SQL> alter table child add constraint fk_parent foreign key (id) references parent on delete cascade;
    Table altered.
    SQL> delete from parent where id = 1;
    delete from parent where id = 1
    ERROR at line 1:
    ORA-04091: table SCOTT.CHILD is mutating, trigger/function may not see it
    ORA-06512: at "SCOTT.BDR_PARENT", line 2
    ORA-04088: error during execution of trigger 'SCOTT.BDR_PARENT'
    SQL>

  • Before delete trigger?

    We are trying to determine who (like in what applicaton) is deleting rows in one table that leaves "orphaned" rows in another.
    We create the following trigger...
    create or replace Trigger EFA_TRG_AUDIT
    before delete on EFA_EXTERNAL_FILE_ATTACHMENT
    for each row
    declare
    OS_USER varchar2 (20);
    HOST varchar2 (20);
    MODULE varchar2 (48);
    SESSION_USER varchar2 (20);
    Begin
    if :old.EFA_LDS_UID is not null then
    SELECT substr(SYS_CONTEXT ('USERENV', 'SESSION_USER'),1,20) into SESSION_USER from dual;
         SELECT module into MODULE from v$session where audsid=userenv('SESSIONID');
         SELECT substr(SYS_CONTEXT ('USERENV', 'HOST'),1,20) into HOST from dual;
         SELECT substr(SYS_CONTEXT ('USERENV', 'OS_USER'),1,20) into OS_USER from dual;
    insert into EFAA_EFA_AUDIT values(
         :old.EFA_UID,
         :old.EFA_SYT_CODE_PARENT,
         :old.EFA_PARENT_KEY,
         :old.EFA_SEQUENCE,
         :old.EFA_FILENAME,
         :old.EFA_DESC,
         :old.EFA_LDS_UID,
         :old.EFA_CREATE_DATE,
         :old.EFA_USR_UID_CREATED_BY,
         :old.EFA_LAST_UPDATE_DATE,
         :old.EFA_USR_UID_UPDATED_BY,
         :old.EFA_FAT_CODE,
         :old.EFA_FILE_SIZE,
         'DELETE',
    HOST,
    OS_USER,
         MODULE,
    User,
         Sysdate);
    end if;
    end;
    This will create an "audit table" which works fine but includes ALL deletes including valid deletes that leave no "orphans" (EFA_LDS_UID).
    The LDS table can have rows that are not related to the EFA so a constraint cannot be used.
    Any ideas?

    no need to clean up the data. just create the FK as NOVALIDATE
    from the SQL Reference manual:
    ENABLE NOVALIDATE ensures that all new DML operations on the constrained data comply with the constraint. This clause does not ensure that existing data in the table complies with the constraint and therefore does not require a table lock

  • How to make row deletion impossible?

    Hello experts,
    I have an editable ALV grid with the following data:
    <b>ACCOUNT     DESCRIPTION      TAX</b>
    1000200        revenue          A0
    1000100        cost             V2
    I want to make the deletion of second row impossible. (I dont want to disable the delete row button)
    How do I achieve this?
    Thanks,
    Yuvaraj

    DATA pt_exclude1 TYPE ui_functions.
        perform exclude_tb_functions CHANGING pt_exclude1.
    *--e.g. initial sorting criteria, initial filtering criteria, excluding
       --functions
        CALL METHOD gr_alvgrid->set_table_for_first_display
          EXPORTING
          I_BUFFER_ACTIVE =
          I_CONSISTENCY_CHECK =
          I_STRUCTURE_NAME =
          IS_VARIANT =
          I_SAVE =
          I_DEFAULT = 'X'
          is_layout = gs_layout
          IS_PRINT =
          IT_SPECIAL_GROUPS =
           IT_TOOLBAR_EXCLUDING = <b>pt_exclude1</b>
          IT_HYPERLINK = ls_hyperlink
          CHANGING
          it_outtab = itab[]
          it_fieldcatalog = gt_fieldcat
          IT_SORT =
          IT_FILTER =
          EXCEPTIONS
          invalid_parameter_combination = 1
          program_error = 2
          too_many_lines = 3
          OTHERS = 4 .
        IF sy-subrc <> 0.
       --Exception handling
        ENDIF.
    *&      Form  exclude_tb_functions
    FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions .
      DATA ls_exclude TYPE ui_func.
      ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_COPY .
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_COPY_ROW .
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_CUT .
      APPEND ls_exclude TO pt_exclude.
    <b>  ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_DELETE_ROW .
      APPEND ls_exclude TO pt_exclude.</b>
      ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_INSERT_ROW .
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_MOVE_ROW .
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_PASTE .
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_PASTE_NEW_ROW .
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_UNDO .
      APPEND ls_exclude TO pt_exclude.
      ls_exclude = cl_gui_alv_grid=>MC_FC_LOC_APPEND_ROW .
      APPEND ls_exclude TO pt_exclude.
    ENDFORM .                    "exclude_tb_functions

  • IW33 how to make dispaly deletions on

    Point remaining is to make Display deletion defaulted as 'ON', whenever user go into the Service Order (IW33)                  . I think that in gui there is a variable assignment which assigns the value as defaulted 'OFF',  so whenever user enters the transaction they need to go and make the display deletion as 'ON'. Please try to investigate that if in some user exits we can make this display deletion as 'ON' or by any other way we can configure this variable to 'ON' and let me know your findings.

    Dantu,
    I'm not sure this will be possible since there may be some ABAP code behind the menu selection that will not run in IW33.
    However, have a look at BADI IWO1_SCEEN_MODIFY or user-exit IWO10006 (FCode exclusion through customer enhancement)
    PeteA

  • How to make the delete button save before deleting?

    Hi all,
    I created a tabular form. What I want to do is when the user click the Delete button, it saves the chagnes AND delete the checked row(s). I tries putting the request "Delete" in the Conditional Processing of the multirow delete process, but I couldn't get it to work.
    Does anyone know how to do that? Thank you very much for the help in advance!

    So, instead of having two separate button, one for Apply Changes and the other for Delete , you want to have one button that will do both. However, if you do that you may miss out on the delete confirmation or end up having a confirmation for both the actions.
    Here is how to do it.
    1. Lets say we will retain the Apply Changes (label) button with request SUBMIT. So make the Condition on Delete button 'Never'.
    2. Now edit the ApplyMRD process and make the condition When Button Pressed = 'SUBMIT'
    3. ApplyMRU will also have the same condition.
    Now both processes should fire on the click of one button.
    BTW, you many have to change the sequence number of the ApplyMRD process and make is greater than the sequence number of the ApplyMRU process.
    Regards,
    Edited by: Prabodh on Aug 17, 2010 8:28 PM

  • How to make 'Key-Enter' trigger (when clicked on enter key)work like 'F8' key?

    Hi . I have another question to be asked.
    Oracle Forms 6i.
    I have a form in which DEFAULT&SMARTBAR is the menu and there are no push buttons.
    In the form, there is a 'field' named as 'ID No'. After entering 'ID No' in the field and click on 'Execute Query' button from the 'DEFAULT&SMARTBAR' menu, all the details of that respective 'ID No' gets displayed in all the other fields. Even if i press 'F8' all the fields gets displayed with the values.
    But i have a requirement, i.e. after entering 'ID No' and click 'Enter' key , i want all the values to be displayed.
    So i created a 'Key-Enter' trigger with the following code:
    BEGIN
      EXECUTE_QUERY;
    END;
    But after entering 'ID No' and click 'Enter' key, the values are not getting displayed.
    What can i do to make this happen?
    Thank You.

    It depends how your form is created. If your ID item is part of the base table block, you can do this.
    On your ID item, create a KEY-NEXT-ITEM trigger:
    if :system.mode = 'ENTER-QUERY' then
        execute_query;
    else
        next_item;
    end if;
    Now
    - User clicks on enter query (via smart bar icon or F7).
    - User enters ID and clicks <enter> key to execute the query.

  • Passsing value to Before Delete Trigger

    I've never seen this done and wanted to see if it's even possible.
    They have created an application using access to fill out a form that a user is signed into. Once the form is created they submit the data to Oracle calling a process as a generic user. They want to be able to capture the user that was logged into Access to update when the trigger is fired and audit record created.
    I'm fairly new to what they are doing here and I think the easiest is just to create a procedure to update the audit table and delete the record, and forget about trying to use a trigger for this purpose.
    Any thoughts out there that might have more experience in this area.
    Thanks

    ...and when that package state is discarded by a patch release the sumbit button on the access form will stop working randomly, and the users will be figure out that they need to click the button twice sometimes and just to be safe always, and you'll end up with loads of duplicated audit entries.
    ...and when someone deletes by logging in as the "generic user" direct from an Access query, or ODBC or SQL*Plus or some random other tool, you'll have no idea who did it.
    The generic user idea is a bad one.

  • How to make display deletions as ON in iw33 ? by default it will be 'OFF" ?

    hi can u pls help me to find out the exat user-exit to achive this functionality
    iw33
    edit---> display deletions -
    > on

    Exits available
    IW33 SAPLCOIH  IPRM0003        E            EXIT_SAPLCOIH_030
                   IPRM0003        E            EXIT_SAPLCOIH_032
                   IWO10001        E            EXIT_SAPLCOIH_001
                   IWO10002        E            EXIT_SAPLCOIH_002
                   IWO10004        E            EXIT_SAPLCOIH_004
                   IWO10005        E            EXIT_SAPLCOIH_005
                   IWO10006        E            EXIT_SAPLCOIH_006
                   IWO10007        E            EXIT_SAPLCOIH_007
                   IWO10008        E            EXIT_SAPLCOIH_008
                   IWO10009        E            EXIT_SAPLCOIH_009
                   IWO10010        E            EXIT_SAPLCOIH_010
                   IWO10011        C            SAPLCOIH+MSF
                   IWO10012        E            EXIT_SAPLCOIH_012
                   IWO10015        E            EXIT_SAPLCOIH_015
                   IWO10016        E            EXIT_SAPLCOIH_016
                   IWO10017        E            EXIT_SAPLCOIH_017
                   IWO10018        E            EXIT_SAPLCOIH_018
                   IWO10018        E            EXIT_SAPLCOIH_019
                   IWO10018        S            SAPLCOIH1180_CUSTSC
                   IWO10020        E            EXIT_SAPLCOIH_020
                   IWO10021        E            EXIT_SAPLCOIH_021
                   IWO10022        E            EXIT_SAPLCOIH_014
                   IWO10025        E            EXIT_SAPLCOIH_025
                   IWO10026        E            EXIT_SAPLCOIH_026
                   IWO10031        E            EXIT_SAPLCOIH_031
                   IWO10033        E            EXIT_SAPLCOIH_033
                   IWO20001        C            SAPLCOIH+PLS
                   IWO20001        E            EXIT_SAPLCOIH_003

  • Question: How to make EDQ Trigger ODI?

    Hi ALL
    I know how to make ODI to Trigger EDQ Job but are threre any wat to make EDQ to trigger ODI Job?
    regards,
    Supanut Srisaksakul

    Assuming ODI jobs can be called from the command line, you could use an External Task and a shell script to invoke them.

  • How to make one-option dropdown list partial trigger?

    There are two dependent dropdown lists. when list one is selected, the other one will get the SelectItems according the value of list one. My question is: when there is only one selectiem in list one (and the hint 'Please select one..."), how to make it partial trigger in the second time? e.g. I first login and select the ONLY one choice in List one, and the List two gets the values. but the data in datasource updated, so I want to choose the List one again, and make the List two get the new values.

    Hi,
    create a JSF binding (Bindings property on the list component) to a managed bean. The in the code that would trigger the PPR, call
    AdfFacesContext.getCurrentInstance().addPartialtarget(theListBindingName);
    If you have a refresh button, then you could use declarative PPR
    Frank

  • Delete trigger not working on delete button

    I have a form (parent) / report (children) combo page with all the default buttons (create, apply changes, delete, cancel) created from the wizard. I've created a before delete trigger on the parent table that basically finds all the children and deletes them. For debugging purposes, I've added some inserts into a test table to make sure my bind variables binding correctly (they are). When I confirm the java script delete and say ok, the insertion of the text for debugging purposes works fine, but the actual deletion of the other records does not. Any ideas why?

    Then it is easy-your delete process is not fireing!!
    Why...there may be many reasons....but I'm pretty sure that process is never fired!
    Look in your page or show us a demo on workspace

  • Help with a Before Delete Triggger

    Hello:
    When I do a delete operation on a table that has the following trigger, it comes up with an error message,
    ":ORA-04091: table INNOBOX.SUGGEST is mutating, trigger/function may not see it
    ORA-06512: at "INNOBOX.DELSUGGEST", line 44
    ORA-04088: error during execution of trigger 'INNOBOX.DELSUGGEST'"
    Can somebody tell me what I am doing wrong?
    CREATE OR REPLACE TRIGGER INNOBOX.delSuggest
    BEFORE DELETE
    ON INNOBOX.SUGGEST
         FOR EACH ROW
              BEGIN
                   INSERT INTO INNOBOX.SUGGEST_LOG
                        Sugg_Log_ID_N,
                        Sugg_No_N,
                        Cat_CD_C,
                        Liaison_CD_C,
                        S_Desc_C,
                        L_Desc_C,
                        S_Stat_CD_C,
                        S_Stat_DT,
                        Benefit_C,
                        Cost_Sav_C,
                        Resol_C,
                        D_Stat_CD_C,
                        D_Stat_DT,
                        ACD_CD_C,
                             Cr_By_ID_C,
                        Cr_DT,
                        Up_By_ID_C,
                        Up_DT     
                   VALUES
                             INNOBOX.Suggest_Log_Seq.NEXTVAL,
                        :old.Sugg_No_N,
                        :old.Cat_CD_C,
                        :old.Liaison_CD_C,
                        :old.S_Desc_C,
                        :old.L_Desc_C,
                        :old.S_Stat_CD_C,
                        :old.S_Stat_DT,
                        :old.Benefit_C,
                        :old.Cost_Sav_C,
                        :old.Resol_C,
                        :old.D_Stat_CD_C,
                             :old.D_Stat_DT,
                             'D',
                             :old.Cr_By_ID_C,
                             :old.Cr_DT,
                             :old.Up_By_ID_C,
                             :old.Up_DT
                   DELETE SUGGEST WHERE Sugg_No_N = :old.Sugg_No_N
              END;
    Thanks.
    Venki

    Hi,
    Try to remove the last line from your trigger :
    DELETE SUGGEST WHERE Sugg_No_N = :old.Sugg_No_N, you delete a line from a table for which there is the same before delete trigger, also there is a muttating trigger.
    HTH,
    Nicolas.

  • Help on delete trigger

    Hi all,
    I have a situation like this
    I have a table like
    SQL> desc system_user
    Name Null? Type
    ID NOT NULL NUMBER(12)
    USER_ID NOT NULL VARCHAR2(30)
    SQL> SELECT * FROM SYSTEM_USER
    2 ORDER BY CTUT_ID;
    CTUT_ID CURRENT_USER_ID
    1 KTYLOR
    2 EXAMPLE
    3 SCOTT
    SQL> DESC ALL_USERS;
    Name Null? Type
    USERNAME NOT NULL VARCHAR2(30)
    USER_ID NOT NULL NUMBER
    CREATED NOT NULL DATE
    What i need to do is i need to have before delete trigger to check the following condition when user try to delete a record in table
    SYSTEM_USER
    1) suppose user is trying to delete a record "SCOTT" IN TABLE
    SYSTEM_USER
    CONDITION SHOULD CHECK THAT IF USER_NAME EXITS IN TABLE "ALL_USER"
    1)IF HE EXITS THEN RAISE ERROR
    2)IF HE IS NOT EXITS THEN DELETE THE RECORD IN TABLE "SYSTEM_USER"
    SO I WROTE A CODE FOR TRIGGER
    SQL> CREATE OR REPLACE TRIGGER TIBD_USER
    2 BEFORE DELETE ON SYSTEM_USER FOR EACH ROW
    3 DECLARE
    4 FOUND_USER NUMBER(2);
    5 BEGIN
    6 SELECT COUNT(*) FROM ALL_USERS
    7 WHERE USERNAME = :OLD.USER_ID;
    8 IF FOUND_USER = 0 THEN
    9 DELETE FROM SYSTEM_USER
    10 WHERE ROWID := :NEW.ROWID;
    11 ELSE
    12 RAISE_APPLICATION_ERROR(-20000,'USER FOUND IN ALL_USERS TABLE');
    13 END IF;
    14 END TIBD_USER;
    15 /
    Warning: Trigger created with compilation errors.
    SQL> SHOW ERRORS
    Errors for TRIGGER TIBD_USER:
    LINE/COL ERROR
    7/1 PL/SQL: SQL Statement ignored
    8/13 PL/SQL: ORA-00920: invalid relational operator
    ANY HELP PLEASE

    1 CREATE OR REPLACE TRIGGER TIBD_USER
    2 BEFORE DELETE ON SYSTEM_USER FOR EACH ROW
    3 DECLARE
    4 FOUND_USER NUMBER(2);
    5 BEGIN
    6 SELECT COUNT(*) INTO FOUND_USER FROM ALL_USERS
    7 WHERE USERNAME = :OLD.USER_ID;
    8 IF FOUND_USER = 0 THEN
    9 DELETE FROM SYSTEM_USER
    10 WHERE ROWID = :OLD.ROWID;
    11 ELSE
    12 RAISE_APPLICATION_ERROR(-20000,'USER FOUND IN ALL_USERS TABLE');
    13 END IF;
    14* END TIBD_USER;
    SQL> /
    Trigger created.
    WHEN I DELETE A RECORD IT IS GIVING ME THAT
    SQL> DELETE FROM SYSTEM_USER
    2 WHERE CTUT_ID = 3;
    DELETE FROM SYSTEM_USER
    ERROR at line 1:
    ORA-04091: table SYSTEM_USER is mutating, trigger/function may not see it
    ORA-06512: at "TIBD_USER", line 7
    ORA-04088: error during execution of trigger 'TIBD_USER'

Maybe you are looking for

  • Appending attachments to PDF form

    When you export a form as a PDF, it would be helpful if any supporting documents attached to the form were exported with the PDF.  It would prevent having to have multiple files/docs for one respondent. 

  • FI -HR

    Dear All How can we get all the amounts which are generated in the HR Pay Roll  to vendor (Employee treated as vendor), wehe we have to integrate to get these... How much amount will be transfer regarding payment (Salary) every month will be shown in

  • Possible for non-Mac users to save and send iPhoto Mail images?

    Will non-Mac users be able to download and save images sent from iPhoto via Mail? Of course they can see the images, but will they be able to save, send, and print them? Thanks.

  • Bought new iPod - will purchased music be OK

    My daughter is on her third iPod and she has a large purchased music collection. I know that iTunes purchased music is OK for up to 5 authorized computers - but what about iPods? Is there a limit to the number of times that she can upgrade the music

  • ITunes will not work with Windows 8.1.

    Is anyone else having trouble with this or know of a fix?