Trigger on either of tables

Hi I have a requirement like this,
desc emp
emp_id, emp_name,
desc emp_details
emp_id, emp_skills
desc emp_log
emp_id statusNow I want to write a trigger which satisfies following criteria
in emp am inserting below data
emp_id  emp_name
1           Sun
3           Gunin emp_skiills am inserting below data
emp_id emp_skills
2          SQL
3          PL/SQLnow with trigger I want data in emp_log table as below
emp_id    status
1             0
2             0
3             0i.e., if either of emp and emp_skills got inserted(in this case 1 and 2) then it should have log in emp_log table and when it is inserting in both then also it should have a single entry
Hope am clear,
Thanks in advance

Check below code:
SQL> create table emp (empid number,ename varchar2(10));
Table created.
SQL> create table emp_skill (empid number,emp_skills varchar2(10));
Table created.
SQL> ed
Wrote file afiedt.buf
  1  create or replace trigger my_trig1 AFTER INSERT ON emp_skill
  2  for each row
  3  declare
  4  v_cnt NUMBER := 0;
  5  begin
  6  SELECT COUNT(*) into v_cnt FROM emp_log WHERE empid = :new.empid;
  7  IF (v_cnt = 0) THEN
  8  insert into emp_log values(:new.empid,0);
  9  END IF;
10* END;
SQL> /
Trigger created.
SQL> ed
Wrote file afiedt.buf
  1  create or replace trigger my_trig AFTER INSERT ON emp
  2  for each row
  3  declare
  4  v_cnt NUMBER := 0;
  5  begin
  6  SELECT COUNT(*) into v_cnt FROM emp_log WHERE empid = :new.empid;
  8  IF (v_cnt = 0) THEN
  9  insert into emp_log values(:new.empid,0);
10  END IF;
11* END;
SQL> /
Trigger created.
SQL> select * from emp;
         1 ABCD
SQL> select * from emp_skill;
         1 PLSQL
SQL> select * from emp_log;
         1          0
SQL> insert into emp values(2,'DCS');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from emp_log;
         1          0
         2          0
SQL> insert into emp_skill values(2,'SQL');
1 row created.
SQL> COMMIT;
Commit complete.
SQL> SELECT * from emp_log;
         1          0
         2          0
SQL> Edited by: AP on Jul 27, 2010 12:45 AM

Similar Messages

  • Error while create trigger on for nested table

    I want to insert a record into a nested table.For this, I created a view for the table, which includes the nested table.It told me ORA-25015 cannot perform DML on this nested table view column.So I created a trigger for the nested table.However, it told me that ORA-25010 Invalid nested table column name in nested table clause.I think my nested table is valid, i don't konw why did it appear this kind of problem?
    My table is
    CREATE TABLE ENT
    ID NUMBER(7) NOT NULL,
    CREATE_DATE VARCHAR2(11 BYTE),
    UPDATE_DATE VARCHAR2(11 BYTE),
    DEPTS VARRAY_DEPT_SEQ
    CREATE OR REPLACE
    TYPE DEPT AS OBJECT
    ID NUMBER(8),
    ANCHOR VARCHAR2(20),
    CREATE OR REPLACE
    TYPE " VARRAY_DEPT_SEQ" as varray(930) of DEPT
    CREATE OR REPLACE VIEW ENT_NESTED_VIEW
    (ID, CREATE_DATE, UPDATE_DATE, DEPTS)
    AS
    select e.ID,cast(multiset(select r.id,r.anchor from ent z, table(z.depts) r where z.ID=e.ID )as varray_dept_seq)
    FROM ENT e
    Then when I created trigger;
    CREATE OR REPLACE TRIGGER EMP.ENT_NESTED_TRI
    INSTEAD OF INSERT
    ON NESTED TABLE DEPTS OF EMP.ENT_NESTED_VIEW
    REFERENCING NEW AS New OLD AS Old PARENT AS Parent
    FOR EACH ROW
    BEGIN
    END ;
    I met the problem: ORA-25010 Invalid nested table column name in nested table clause
    Could you please tell me the reason
    Thank you!
    My insert SQL is:
    insert into table(select depts from ent_nested_view where id=1856) values(varray_dept_seq(dept(255687,'AF58743')))
    Message was edited by:
    user589751

    Hi,TongucY
    Compared with the "Referencing Clause with Nested Tables" part of this reference -
    http://psoug.org/reference/instead_of_trigger.html, I found the answer of this
    quesion. That is "CREATE OR REPLACE TYPE " VARRAY_DEPT_SEQ" as[b] varray(930) of
    DEPT". It turns to be a varying array, not a nested table. It should be "CREATE OR
    REPLACE TYPE " VARRAY_DEPT_SEQ" as table of DEPT". That is OK. Thank you very
    much!
    While there is an another question, if I create a varying array like" CREATE OR
    REPLACE TYPE " VARRAY_DEPT_SEQ" as[b] varray(930) of DEPT " and I want to insert
    a record into the varying array, which the record has been existed.The method that
    create a view and a trigger seems not to be effective.
    For instance,
    There is a record in the table
    ID:1020
    CREATE_DATE:2005-10-20
    UPDATE_DATE:2007-2-11
    DETPS: ((10225,AMY))
    I want to ask this record to be
    ID:1020
    CREATE_DATE:2005-10-20
    UPDATE_DATE:2007-2-11
    DETPS: ((10225,AMY),(10558,TOM))
    How should I do?
    Could you please help me?
    Best regards.
    Message was edited by:
    user589751

  • How To Perform Parallel UPDATE When Trigger is ENABLE On Table.

    select *from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Linux: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - ProductionIs there any way to perform PARALLEL UPATE on a table which has a trigger?
    One of my ETL performs a large UPDATE (14 Million update) everyday on a production hot table. Eventhough PDML is enable at session level (also TABLE.DEGREE=8), Oracle is doing serialized UPDATE.
    As per Oracle documents, it is documented behavior.
    Here is my Execution plan when i put the trigger ENABLE
    | Id  | Operation              | Name                | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |    TQ  |IN-OUT| PQ Distrib |
    |   0 | UPDATE STATEMENT       |                     |       |       |  6443 (100)|          |       |       |        |      |            |
    |   1 |  UPDATE                | ACCOUNT             |       |       |            |          |       |       |        |      |            |
    |*  2 |   PX COORDINATOR       |                     |       |       |            |          |       |       |        |      |            |
    |   3 |    PX SEND QC (RANDOM) | :TQ10000            | 72487 |  3610K|  6443   (3)| 00:01:18 |       |       |  Q1,00 | P->S | QC (RAND)  |
    |*  4 |     FILTER             |                     |       |       |            |          |       |       |  Q1,00 | PCWC |            |
    |   5 |      PX BLOCK ITERATOR |                     | 72487 |  3610K|  6443   (3)| 00:01:18 |   KEY |   KEY |  Q1,00 | PCWC |            |
    |*  6 |       TABLE ACCESS FULL| ACCOUNT             | 72487 |  3610K|  6443   (3)| 00:01:18 |   KEY |   KEY |  Q1,00 | PCWP |            |
    Predicate Information (identified by operation id):
         8 - filter("SET_OF_BOOKS"='1' AND "GL_BATCH_ID">(-10) AND ("JOURNAL_ENTRY_TYPE_ID"<2400 OR
                  "JOURNAL_ENTRY_TYPE_ID">=3000) AND "ACCOUNTING_DATE">=TO_DATE(' 2010-08-11 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND "ACCOUNTING_DATE"<TO_DATE(' 2010-08-12 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))When i disable trigger
    | Id  | Operation                | Name     | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
    |   0 | UPDATE STATEMENT         |          |   726 | 27588 | 11899   (2)| 00:02:23 |        |      |            |
    |   1 |  PX COORDINATOR          |          |       |       |            |          |        |      |            |
    |   2 |   PX SEND QC (RANDOM)    | :TQ10001 |   726 | 27588 | 11899   (2)| 00:02:23 |  Q1,01 | P->S | QC (RAND)  |
    |   3 |    INDEX MAINTENANCE     | ACCOUNT  |       |       |            |          |  Q1,01 | PCWP |            |
    |   4 |     PX RECEIVE           |          |   726 | 27588 | 11899   (2)| 00:02:23 |  Q1,01 | PCWP |            |
    |   5 |      PX SEND RANGE       | :TQ10000 |   726 | 27588 | 11899   (2)| 00:02:23 |  Q1,00 | P->P | RANGE      |
    |   6 |       UPDATE             | ACCOUNT  |       |       |            |          |  Q1,00 | PCWP |            |
    |   7 |        PX BLOCK ITERATOR |          |   726 | 27588 | 11899   (2)| 00:02:23 |  Q1,00 | PCWC |            |
    |*  8 |         TABLE ACCESS FULL| ACCOUNT  |   726 | 27588 | 11899   (2)| 00:02:23 |  Q1,00 | PCWP |            |
    Predicate Information (identified by operation id):
       8 - filter("SET_OF_BOOKS"='1' AND "GL_BATCH_ID">(-10) AND ("JOURNAL_ENTRY_TYPE_ID"<2400 OR
                  "JOURNAL_ENTRY_TYPE_ID">=3000) AND "ACCOUNTING_DATE">=TO_DATE(' 2010-08-11 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND "ACCOUNTING_DATE"<TO_DATE(' 2010-08-12 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))I cannot disable trigger due to some business reasons.
    Is there any way to speed up UPDATE ?

    No, you cannot perform parallel dml with a trigger present.
    If you are updating the bulk of the rows and can take an outage, you can
    disable the trigger, perform the update, enable the trigger
    OR
    copy to another table, performing the update in the select, rename the tables and add the trigger on the new table
    Hemant K Chitale

  • How can i write the trigger for Global Temporary Table

    Hi Grus,
    How can i write the trigger for Global Temporary Table.
    I was created the GTT with trigger using the below script .
    CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP
    EMP_C_NAME VARCHAR2(20 BYTE)
    ON COMMIT PRESERVE ROWS;
    CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
    BEFORE DELETE OR UPDATE OR INSERT
    ON GLOBAL_TEMP
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME);
    END;
    trigger was create successfully, but the wouldn't insert into to EMPNAME Table..
    Please guide whether am correct or not? if not kindly give a correct syntax with example
    Thanks in Advance,
    Arun M M

    BEGIN
    INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME);
    END;
    you are referencing old value in insert stmt.
    BEGIN
    INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
    END;then run ur application it works fine...
    CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP
    EMP_C_NAME VARCHAR2(20 BYTE)
    ON COMMIT PRESERVE ROWS;
    CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
    BEFORE DELETE OR UPDATE OR INSERT
    ON GLOBAL_TEMP
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    dbms_output.put_line(:OLD.EMP_C_NAME||'yahoo');
    INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
    dbms_output.put_line(:OLD.EMP_C_NAME);
    END;
    create table EMPNAME as select * from GLOBAL_TEMP where 1=2
    insert into GLOBAL_TEMP values('fgfdgd');
    commit;
    select * from GLOBAL_TEMP;
    select * from EMPNAME;
    output:
    1 rows inserted
    commit succeeded.
    EMP_C_NAME          
    fgfdgd              
    1 rows selected
    EMP_C_NAME          
    fgfdgd              
    1 rows selectedgot it Arun
    Edited by: OraclePLSQL on Dec 28, 2010 6:07 PM

  • Can i  create IN/UP/DE Trigger on a existing table having more than 2L rows

    Hi All,
    Can i create a INSERT/UPDATE/DELETE Trigger on a existing table having more than 2 lacs records ? if yes (is that works for only some kind of triggers? or for all ?). if not, tell me the reasons and limitations with guidelines.
    Thanks in Advance.

    Hi,
    Sure; you can create new triggers for tables that already have rows. The type of trigger and the number of rows already in the table don't matter.
    Try it. If the trigger works with a small table in your Development database, then there's no reason to expect it won't work on a larger table in your Production datbase.

  • Trigger on SYS owned tables/views

    Hello DBA's,
    I need to achive something.. for which I have to write a trigger on SYS owned tables/views.
    My question is, IS IT POSSIBLE TO WRITE A TRIGGER ON SYS OWNED OBJECTS?. If so please provide me simple example.
    Depending on the value which will be inserted or updated into to this sys.views/sys.tables, I have to submit "job" which will inturn does some operation depending on the "value" which was inserted or updated on this view/table.
    Thankz in advance..
    Binny

    Justin,
    I will give some simple example...
    User-1 is created procedure... it will be in valid state.. after some time this procedure will be invalidated...(due to some other procedure creation, etc)..
    Stage1, during successful creation of procedure the status will be VALID (in DBA_OBJECTS)
    Stage2, the status will be INVALID..
    I need to write a trigger for this status change in dba_objects.. The status change will be caused due to some other operation..
    Is it possible to write a trigger at the point of status change? if so how?.
    This is the simple example I have remembered.
    Let me about this..
    Thankz
    Binny

  • Custom Trigger issues on PO_DISTRIBUTIONS_ALL table... null id?

    Hi...I have a custom after insert trigger on the PO_DISTRIBUTIONS_ALL table
    It is having an issue with getting the req_distribution_id
    I took out all the code and left in just a test, which only inserts the id into a test table. But it is always null! Can someone tell me why? Because there is an ID when created, and I see it after I query the table when it is finished. But I figured, after insert it will be there!
    Below is the trigger...
    create or replace
    TRIGGER APPS.xxmc_po_distributions_auir
    AFTER INSERT OR UPDATE ON PO_DISTRIBUTIONS_ALL
    REFERENCING NEW AS new OLD AS old
    FOR EACH ROW
    DECLARE
    v_trigger_location VARCHAR2(2000):= 'Declaration';
    v_error_message VARCHAR2(2000);
    BEGIN
    delete from test_table;
    insert into test_table values(to_char(:new.req_distribution_id));
    END;
    This enters null every time into the table. Why is that?
    -J

    OK my new trigger has the dml statements in a procedure and it still fails. The ID is always null. Below is the trigger...why is the id coming up null???
    :new.req_distribution_id should never be a null value in my opinion, right?
    create or replace
    TRIGGER APPS.xxmc_po_distributions_auir
    AFTER INSERT OR UPDATE ON PO_DISTRIBUTIONS_ALL
    REFERENCING NEW AS new OLD AS old
    FOR EACH ROW
    DECLARE
    v_trigger_location VARCHAR2(2000):= 'Declaration';
    v_error_message VARCHAR2(2000);
    /* Error Tracking local variables */
    v_user_id NUMBER := FND_GLOBAL.User_Id;
    v_inv_record_id_s NUMBER := 0;
    v_mycall_status VARCHAR2(20);
    v_myerror_msg VARCHAR2(200);
    v_ric_code VARCHAR2(10);
    v_tracking_id VARCHAR2(200);
    v_source_system xxmc_track_summary.source_system%TYPE := 'XXMC_CRM';
    v_destination_system xxmc_track_summary.destination_system%TYPE := 'XXMC_CRM';
    v_rice_name xxmc_track_summary.rice_object_name%TYPE := 'E120';
    v_failure_record_count xxmc_err_track_det.error_count%TYPE := 0;
    v_module_name xxmc_err_track_det.procedure_name%TYPE := 'XXMC_PO_DISTRIBUTIONS_AUIR';
    v_stg_tablename xxmc_track_summary.staging_table_name%TYPE := '';
    v_processed INTEGER := 0;
    v_failed INTEGER := 0;
    v_total INTEGER := 0;
    v_commit INTEGER := 0;
    e_error_tracking_exception EXCEPTION;
    CURSOR c_get_req_line_info(p_req_distribution_id IN NUMBER) IS
    SELECT PORH.SEGMENT1
    , porh.attribute1 po_heading_att1
    , porl.line_num
    , porl.destination_context
    , porl.attribute1
    , porl.attribute3
    , porl.attribute4
    , porl.attribute5
    , porl.attribute6
    , porl.attribute7
    , porl.attribute8
    , porl.attribute9
    , porl.attribute10
    , porl.attribute11
    , porl.attribute12
    , porl.requisition_line_ID
    , to_char(porl.creation_date, 'mm/dd/yyyy hh24:mi:ss') format_create_date_line
    FROM PO_REQ_DISTRIBUTIONS_ALL PORD
    , PO_REQUISITION_LINES_ALL PORL
    , PO_REQUISITION_HEADERS_ALL PORH
    WHERE PORD.DISTRIBUTION_ID = p_REQ_DISTRIBUTION_ID
    AND PORL.REQUISITION_LINE_ID = PORD.REQUISITION_LINE_ID
    AND PORH.REQUISITION_HEADER_ID = PORL.REQUISITION_HEADER_ID
    i number := 0;
    TEMP NUMBER;
    BEGIN
    v_trigger_location := 'Beginning of trigger body';
    KMG_WRITE('INSERTING IN XXMC TRIGGER ON PO DISTRIBUTIONS AT '
    || TO_CHAR(SYSDATE, 'MM/DD/YYYY HH24:MI:SS')
    || ' REQ_DISTRIBUTION_ID = '
    || NVL(TO_CHAR(:new.req_distribution_id), 'VALUE IS NULL') );
    xxmc_tracking_pkg.create_source_tracking_record(
    p_tracking_id => v_tracking_id
    ,p_source_system => 'XXMC_CRM'
    ,p_destination_system => 'XXMC_CRM'
    ,p_rice_object_name => v_rice_name
    ,p_creation_date => sysdate
    ,p_created_by => v_user_id
    ,p_transaction_type => 'XXMC_CRM'
    ,p_status => 'INFLIGHT'
    ,p_if_direction => 'O'
    ,p_sub_status => 'XXMC_PROCESSING_IN_EBS'
    ,p_src_total_records => 0
    ,p_call_status => v_mycall_status
    ,p_error_msg => v_myerror_msg);
    IF v_mycall_status <> 'S' THEN
    RAISE e_error_tracking_exception;
    END IF;
    TEMP:='AAA';
    i := 0;
    FOR r IN c_get_req_line_info(:new.req_distribution_id) LOOP
    i := i + 1;
    UPDATE po_lines_all pol
    SET attribute_category = r.destination_context
    , Attribute1 = r.attribute1
    , Attribute3 = r.attribute3
    , Attribute4 = r.attribute4
    , Attribute5 = r.attribute5
    , Attribute6 = r.attribute6
    , Attribute7 = r.attribute7
    , Attribute8 = r.attribute8
    , Attribute9 = r.attribute9
    , Attribute10 = r.attribute10
    , Attribute11 = r.attribute11
    , Attribute12 = r.attribute12
    WHERE pol.po_line_id = :new.po_line_id;
    UPDATE po_headers_all poh
    SET attribute1 = r.po_heading_att1
    WHERE poh.po_header_id = :new.po_header_id;
    END LOOP;
    EXCEPTION
    WHEN e_error_tracking_exception THEN
    kmg_write('Could not create source tracking record in XXMC PO DISTRIBUTIONS trigger. Status = '
    || v_mycall_status || ' Msg = ' || v_myerror_msg);
    RAISE_APPLICATION_ERROR (
    num=> -20003,
    msg=> 'XXMC PO DISTRIBUTIONS trigger error in '
    || ' create_source_tracking_record '
    || v_myerror_msg);
    WHEN OTHERS THEN
    v_error_message := SQLERRM;
    kmg_write('Error in XXMC PO DISTRIBUTIONS trigger. ' || v_error_message);
    xxmc_tracking_pkg.log_then_report_errors(
    p_tracking_id => v_tracking_id
    ,p_source_system => v_source_system
    ,p_destination_system => v_destination_system
    ,p_det_record_id => v_inv_record_id_s
    ,p_message_name => 'XXMC_PO_DISTRIBUTIONS'
    ,p_message_description => 'XXMC_PO_DISTRIBUTIONS'
    ,p_message_text => ltrim(rtrim(v_error_message))
    ,p_last_update_date => sysdate
    ,p_procedure_name => v_module_name
    ,p_staging_table_name => v_stg_tablename
    ,p_status => 'FAILED'
    ,p_sub_status => 'XXMC_PROCESSING_IN_EBS'
    ,p_src_success_records => v_processed
    ,p_src_failed_records => v_failed
    ,p_dest_success_records => v_processed
    ,p_dest_failed_records => v_failed
    ,p_error_count => v_failed
    ,p_call_status => v_mycall_status
    ,p_error_msg => v_myerror_msg
    ,p_key_field_value => v_tracking_id);
    RAISE_APPLICATION_ERROR (
    num=> -20001,
    msg=> 'Error encountered in XXMC PO DISTRIBUTIONS AUIR Trigger '
    || ' Date = ' || to_char(sysdate, 'mm/dd/yyyy hh24:mi:ss')
    || ' SQLERRM = ' || v_error_message);
    END;

  • How many trigger possible on one table?

    How many trigger possible on one table?

    Hi,
    shiv kumar wrote:
    How many trigger possible on one table?There's no limit.
    If you have more than one trigger that fires at the same time (for example "BEFORE INSERT OR UPDATE ... FOR EACH ROW"), ask yourself why you want or need 2 separate triggers, rather than one (which maybe calls two sparate procedures).

  • 2.1EA2 - Still problems with trigger text tab on table panel

    I'm currently running SQLDeveloper 2.1 EA2 and I'm experiencing problems to display text of tables triggers.
    In fact I have found that file displaying this text has an mistake : It's assumed that trigger owner is the same as table owner.
    In file oracle/dbtools/raptor/oviewer/base/xml/tables.xml of extension oracle.sqldeveloper.oviewer.jar version11.1.1.63.10.
    This file contains an section dedicated to triggers :
    select dt.trigger_NAME, dt.trigger_type, dt.triggering_Event, dt.status, :OBJECT_OWNER sdev_link_owner,
    dt.trigger_NAME sdev_link_name,'TRIGGER' sdev_link_type
    from DBA_triggers dt
    where dt.table_owner = :OBJECT_OWNER
    and dt.table_name = :OBJECT_NAME;
    And the source part :
    select text sql
    from dba_source
    where name=:TRIGGER_NAME
    and owner=:OBJECT_OWNER;
    I Think the glitches is the owner=:OBJECT_OWNER.
    I made some tests by replacing the table.xml in archive (I know it's hugly). My modifications are :
    1) add an trigger_owner column in firsts selects
    2) use :TRIGGER_OWNER instead of :OBJECT_OWNER
    This seems to solve problems.
    I don't know how to report this as a bug, bu I hope that someone of the devel team will push it forward to solve the problem on 2.1 final.

    It's there; it's just very small. Consider either giving it some rows or column int values or a preferred size, or putting it in a JScrollPane with a preferredSize set.
    another thought is to use a BorderLayout for the whole thing, and place the JScrollPane/JTextArea BorderLayout.CENTER, put the JTextField and JLabels in a JPanel using GridBag and placing this into the main BorderLayout.NORTH, and placing the buttons into their own panel which is added to the main BorderLayout.SOUTH.
    Edited by: Encephalopathic on Sep 24, 2008 9:51 AM

  • Mutating Trigger error while updating table

    Hi Guys,
    I am updating one table and after trigger also fire at the same time. Now, I want to avoid mutating trigger error. Can any one help me on this.
    Thanks in advance!
    Regards,
    -LRK

    You'll have to read these articles first, they explain what's the problem and how to deal with it:
    http://www.oracle-base.com/articles/9i/MutatingTableExceptions.php
    http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551198119097816936
    but, as Saubhik already said, using Oracle's AUDIT functionality would be the way to go.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_4007.htm
    Using an autonomous transaction can result in corrupted data or unexpected errors, stay away from them if you want to use them in order to bypass/hide your mutating table error.

  • Using an on update or insert trigger on a SAP table

    Hi all,
    A question for you regarding using a database trigger in and SAP system. 
    We are needing to export data for our datawarehouse.  Currently we export all the data.  That data is getting quite large tho and time is becoming an issue.
    One suggestion has been to add a custome field to an existing SAP table to hold a flag to indicate the record has changed but not been extracted.  Thenput a trigger on the table in question so that the new field is updated upon update or insert of the record.  Then when the extract runs, it will only extract those records with the flag set, then reset the flag.
    we are using ERP 6 and SQL Server 2005 (or soon to as we will be upgrading next month).
    Any suggestions regarding triggers?  Or other options for flagging changed records in large table so we don't have to extract all records every time?
    Thanks
    Laurie
    Edited by: Laurie McGinley on Oct 27, 2008 10:51 PM

    Hi Laurie,
    just really shouldn't consider to put triggers into your application.
    The problem here is the very nature of triggers to do things 'in the background'.
    If you have problems due to the trigger, you won't see it anywhere in the SAP environment.
    In a while you probably forget about the trigger at all and then nobody can see, what is happening to the database, just because something is changed "in the background".
    Besides that you don't get support for this from SAP, you will make your life a lot harder.
    Tabledefinitions may change - your trigger might break.
    Put application logic where it belongs - to the application layer!
    regards,
    Lars

  • How to retreive dynamicly  the name of  a trigger associated with a table

    Hi,
    Comming from Ms-Access and SQL Server, i use triggers (build by omwb) to get automaticaly a new value to primary keyes (during the insert phase).
    Is it possible to retreive by sql, schema... the name of a trigger associate to a specific col in a specific table ?
    Regards.

    Hi,
    Comming from Ms-Access and SQL Server, i use triggers (build by omwb) to get automaticaly a new value to primary keyes (during the insert phase).
    Is it possible to retreive by sql, schema... the name of a trigger associate to a specific col in a specific table ?
    Regards. For update triggers try this:
         select trigger_name from all_trigger_cols
         where
              table_owner = 'DEMO' and
              table_name = 'DEMO_BILLING' and
              column_name = 'PAID' and
              column_list = 'YES';
    For insert triggers you can refer to all_triggers.
    Regards,
    Robin.
    Robin Bothwell
    Software Developer
    Compuware/Numega
    1-800-462-7740x16609
    <http://www.compuware.com/products/devpartner/db/visualstudio.htm>

  • 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 apply a Trigger on a Transcation Table

    Hi Friends,
    I have one requirement from my client.
    let me explain u the scenario..
    if a person is apply for a loan . when he clicks on the submit button it goes to the approvers.. it means it will go tho the transacation tables.
    my requirement is if a person applies for the same loan two times before any action taken place for the previous applied loan .. then it should stop the user moving forward.saying your previous loan is pending for approval.
    Technical:-
    i wrote one package for it.. and called it in a trigger for validation
    create or replace package body xx_transcation_pkg is
    function get_trans(p_person_id in number)
    return varchar2
    is
    cursor c1 is
    SELECT htr.transaction_id
    FROM per_analysis_criteria pac,
    hr_api_transactions htr,
    hr_api_transaction_steps hts,
    hr_api_transaction_values htrv
    WHERE htr.transaction_id = hts.transaction_id
    AND hts.transaction_step_id = htrv.transaction_step_id
    AND htrv.NAME LIKE 'P_ANALYSIS_CRITERIA_ID%'
    AND htr.process_name = 'VEHICLE_LOAN'
    AND htr.selected_person_id = TO_NUMBER (p_person_id)
    AND pac.analysis_criteria_id = htrv.number_value
    AND htr.status = 'Y'
    AND hts.transaction_step_id =
    (SELECT hts.transaction_step_id
    FROM hr_api_transaction_values htv,
    hr_api_transaction_steps hts
    WHERE htv.transaction_step_id = hts.transaction_step_id
    AND hts.transaction_id = htr.transaction_id
    AND htv.varchar2_value IN ('INSERT', 'UPDATE'))
    GROUP BY htr.transaction_id;
    --variable declaration
    l_value number;
    begin
    for i in c1
    loop
    l_value:=i.transaction_id;
    if
    l_value is not null
    then
    return('Flag1');
    else
    return('Flag2');
    end if;
    end loop;
    end;
    end xx_transcation_pkg;
    and my trigger is
    CREATE OR REPLACE TRIGGER TEST_RL
    BEFORE DELETE OR INSERT OR UPDATE
    ON PER_ANALYSIS_CRITERIA REFERENCING NEW AS N OLD AS O
    FOR EACH ROW
    declare
    p_person_id number;
    v_id_flex_num number;
    l_flag varchar2(100);
    begin
    v_id_flex_num := (:n.ID_FLEX_NUM);
    if
    v_id_flex_num=50430
    then
    p_person_id:=(:n.segment30);
    begin
    select xx_transcation_pkg.GET_TRANS(p_person_id) into
    l_flag from dual ;
    end;
    if
    l_flag='Flag1' then
    raise_application_error(-20002,'Your Previous Loan Application is pending for Approval');
    end if;
    end if;
    end TEST_RL;
    Now my problem is
    This Trigger is not working in the scenarios
    i) suppose person applies for a loan today and once again applies the same loan without changing anydata in the fileds then trigger is not validating.. transacation is taking place..
    eg:- person:- xx
    loan amount:-200
    click on submit it goes to approver
    second time person:- xx
    loan amount:- 200
    click on submit it goes to approver
    Trigger is working in the scenarios
    eg :- person:- xx
    loan amount :- 200
    click on submt it goes to approver
    second time person:- xx
    loan amount :- 210
    click on submit ( error message :- Your Previous Loan Application is pending for approval).
    Can anyone help me out, how to handle this
    Thanks in advnace

    Okay let me give some recommendations.
    I would suggest you don't use a database trigger. Triggers can mask unhandled exceptions (making it difficult to debug), aren't aware of p_validate architecture in HRMS APIs, can be easily accidentally disabled, and function at a level much lower than the 'business process' layer that you're interested in.
    The recommended (and supported) way to add custom validation in Oracle HRMS is to use API User Hooks. Your use-case is perfect for API User Hooks. The hr_sit_api package has an API for both create_sit and update_sit. Both of these APIs have 'before' and 'after' user hooks.
    If I've understood your requirements (and I'm still not sure I do completely), the following approach could work:
    a) Implement a 'before' hook on hr_sit_api.update_sit.
    b) In this hook add a check to see if the current p_person_analysis_id is being updated in hr_api_transactions. You'll also need to check the timing of what happens when the final approver approves: if the hr_api_transactions row still exists at the time the API is called to commit the update your hook will raise the same error. I have a feeling the hr_api_transaction data is already removed at this point but just one for you to check.
    c) If it is currently being updated, raise the error (use fnd_message.set_name and fnd_message.raise_error)
    This will prevent the user from updating the SIT if an update is already pending.

  • PL/SQL Trying to update a table through trigger on the same table

    Hi everyone my name is Edwin and I'm new to this forum. I hope I can learn a lot from this community and over time contribute to it.
    The problem I'm facing at the moment is a tough one. I need to update a table (table a) with a value called block_id. This block_id is generated by a procedure I have written myself, the end result is stored in another table (table b). This block_id needs to be generated after certain rows of table a get updated with a trans_id. The trans_id is all the same for these rows in table a, but the generated block_id isn't. In my code I use an after update on collumn a of table a trigger. So if the the collumn gets updated the trigger fires. The trigger calls the procedure that generates the block_id and the procedure generates table b with all the block_id's. But then I want to update the rows in table a with the generated block_id in table b. The problem is that this self-deadlocks.
    You might think that this would call a recursive trigger, but I have written code in the trigger that checks if the block_id isn't allready filled in on table a.
    Also I really need all the values wich get updated (table a), so I believe a before update is also out of the question.
    And the first update of table a is done through an erp-packet and I can't get at that code, otherwise I would just have run my code from there.
    Message was edited by:
    user625855

    CREATE OR REPLACE TRIGGER block_id_trigger AFTER UPDATE ON unload_details_tab
    DECLARE
    current_transport_id NUMBER;
    check_value NUMBER;
    check_block_id NUMBER;
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
    current_transport_id := get_curent_trans_id; --function that gets the current transport_id
    check_value := check_site_and_directive(current_transport_id); --function checks if this transport_id should have a block_id
    check_block_id := check_for_block_id(current_transport_id); --function checks if there isn't allready a block_id set.
    IF check_value = 1 AND check_block_id = 0 THEN
    create_blok_id_table(current_transport_id); --this procedure creates the blok_id in temptable
    UPDATE unload_details_tab a SET a.block_id = (SELECT DISTINCT b.blok_id FROM temptable b WHERE b.mark = a.mark_1) WHERE a.transport_id = current_transport_id; --this statement should update the table back, if I leave it out everything works fine, but when I leave it I get the self-deadlock error.
    ELSE
    null;
    END IF;
    END block_id_trigger;
    Ok, I cleaned the code somewhat.
    user625855

Maybe you are looking for

  • TDS Business place & Secotion code issue

    hai, In FB60 we are making entry with TDS. Here business place and section code is required to fillup. If it is not maintained at the time of posting, then there will be a problem in Remittance challan creation. If we call the document which was not

  • Problems in running the servlet in Oracle JDeveloper

    I have problems in running servlets(http servlet) in oracle jDeveloper. Heres the code package view; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.*; import javax.servlet.http.*; public class Servlet1 extends HttpServle

  • To add serial number column

    Dear Experts,                     I herewith attachedc my  codings i waht to add serial number how to do that i have done something but it is giving all zero values.,.,., *& Report  ZAPPRAISAL_LAG REPORT  ZAPPRAISAL. *Declaration of type-pools TYPE-P

  • Output through camera problem

    I need to make a VHS dub of a sequence. I have a firewire out of my computer going to my camera and then the A/V cable out of the camera into the VHS. The signal/picture is there but it drops out (screen goes blue) randomly. Any obvious things to che

  • TREX problem: Rapid Installer 2.0

    First I try to install EP 6.0 SR1 with Rapid Installer 2.0, I got an trex error in the installation. In this forum (read by Nicky Gromeleit) I got the information that installing TREX in rapid installation is not possible so I try again the following