Update by after insert trigger

I need to update each new inserted row of data by checking if there were same values in the table. So I tried the After Insert Trigger with the code below :
CREATE OR REPLACE TRIGGER approve_checker
after insert on TBL_BILL
for each row
declare
counter integer;
begin
SELECT COUNT() INTO counter FROM TBL_BILL WHERE issue_date=:NEW.issue_date AND wagon_no=:NEW.wagon_no ;*
IF( counter > 1)
THEN
UPDATE TBL_BILL SET approved = 2 WHERE id = :NEW.id;
END IF;
end approve_checker;
But errors accured :
ORA-04091: table RAIL.BILL is mutating, trigger/function may not see it
ORA-06512: at "RAIL.APPROVE_CHECKER", line 4
ORA-04088: error during execution of trigger 'RAIL.APPROVE_CHECKER'
Any help appreciated.

You cannot SELECT from the table on which the row-level trigger is defined, nor can you UPDATE a table on which the row-level trigger is defined. If you are inserting multiple rows in a single INSERT statement, Oracle can't be sure what rows to update and/or select.
Is there a reason that you wouldn't just create a unique constraint to enforce this condition?
Justin

Similar Messages

  • Using Database Change Notification instead of After Insert Trigger

    Hello guys! I have an after insert trigger that calls a procedure, which in turn is doing an update or insert on another table. Due to mutating table errors I declared the trigger and procedure as autonomously transactional. The problem is, that old values of my main tables are inserted into the subtable since the after insert/update trigger is fired before the commit.
    My question is how can I solve that and how could I use the change notification package to call my procedure? I now that this notification is only started after a DML/DDL action has been commited on a table.
    If you could show me how to carry out the following code with a Database Change Notification I'd be delighted. Furthermore I need to know if it suffices to set up this notification only once or for each client seperately?
    Many thanks for your help and expertise!
    Regards,
    Sebastian
    declare
    cnumber number (6);
    begin
    select count(*) into cnumber from (
    select case when (select date_datum
        from
          (select f.date_datum,
            row_number() over (order by f.objectid desc) rn
          from borki.fangzahlen f
          where lng_falle      = :new.lng_falle
          and int_fallennummer = :new.int_fallennummer
          and lng_schaedling   = :new.lng_schaedling
          and date_datum       > '31.03.2010'
        where rn=1) < (select date_datum
        from
          (select f.date_datum,
            row_number() over (order by f.objectid desc) rn
          from borki.fangzahlen f
          where lng_falle      = :new.lng_falle
          and int_fallennummer = :new.int_fallennummer
          and lng_schaedling   = :new.lng_schaedling
          and date_datum       > '31.03.2010'
        where rn=2) then 1 end as action from borki.fangzahlen
            where lng_falle      = :new.lng_falle
            and int_fallennummer = :new.int_fallennummer
            and lng_schaedling   = :new.lng_schaedling
            and date_datum       > '31.03.2010') where action = 1;
    if cnumber != 0 then
    delete from borki.tbl_test where lng_falle = :new.lng_falle
    and int_fallennummer = :new.int_fallennummer
    and lng_schaedling   = :new.lng_schaedling
    and date_datum       > '31.03.2010';
    commit;     
    pr_fangzahlen_tw_sync_sk(:new.lng_falle, :new.int_fallennummer, :new.lng_schaedling);

    It looks like you have an error in line 37 of your code. Once you fix that the problem should be resolved.

  • Calling of Stored Procedure in After Insert Trigger

    Can I call a Stored Procedure in After Insert Trigger ?
    Please send a sample code (good example) of After Insert Trigger.
    Thanks.

    Kishore,
    I have two table WLCS_ORDER, WLCS_ORDER_LINE
    WLCS_ORDER - It holds order header information like
    ORDER_ID
    CUSTOMER_ID
    TRANSACTION_ID
    STATUS
    ORDER_DATE
    SHIPPING_METHOD
    SHIPPING_AMOUNT
    SHIPPING_CURRENCY
    PRICE_AMOUNT
    PRICE_CURRENCY
    SHIPPING_GEOCODE
    SHIPPING_STREET1
    SHIPPING_STREET2
    SHIPPING_CITY
    SHIPPING_STATE
    SHIPPING_COUNTRY
    SHIPPING_POBOX
    SHIPPING_COUNTY
    SHIPPING_POSTAL_CODE
    SHIPPING_POSTAL_CODE_TYPE
    SPECIAL_INSTRUCTIONS
    SPLITTING_PREFERENCE
    ORDER_SUBTOTAL
    WLCS_ORDER_LINE - It holds all order lines information like
    ORDER_LINE_ID
    QUANTITY
    PRODUCT_ID
    TAX_AMOUNT
    TAX_CURRENCY
    SHIPPING_AMOUNT
    SHIPPING_CURRENCY
    UNIT_PRICE_AMOUNT
    UNIT_PRICE_CURRENCY
    MSRP_AMOUNT
    MSRP_CURRENCY
    DESCRIPTION
    ORDER_ID
    TOTAL_LINE_AMOUNT
    Relation between WLCS_ORDER, WLCS_ORDER_LINE is one to many.
    For each WLCS_ORDER row, one or more order lines will insert into WLCS_ORDER_LINE table.
    For each new row in WLCS_ORDER table, I have to update the following columns in both the tables with my maths.
    WLCS_ORDER
    shipping_amount
    price_amount
    order_subtotal
    WLCS_ORDER_LINE
    shipping_amount
    I thought I can do this in after insert trigger, But if it is not possible, Please give the best way to fulfill this requirement.
    I appreciate your help.
    Have a great day.
    Srinivas

  • After Insert Trigger with DML on the subject table?

    I am trying to set up e-mail notifications, so I created a procedure, which accepts the argument of an id. In the procedure, it queries the table and sends out mail based on the result set. (in the trigger, I pass in the value of :NEW.id). The procedure then queries the table for that row id.
    First, for the after update I was getting the error:
    ORA-04091: table is mutating, trigger/function may not see it ORA-06512
    So, I was advised to do in the declare block: pragma autonomous_transaction; I did that, and that solved the problem there. SO I did the same in the after insert trigger, but then I get the error:
    ORA-00060: deadlock detected while waiting for resource ORA-06512
    I asked our DBA and he said you are not able to query the table of which the trigger is a subject of. I thought it would be possible since its After insert or update?
    Can anyone offer any suggestions ? :)
    Thanks,
    Trent

    Any reason why it would work in an after update trigger then?
    So, I was advised to do in the declare block: pragma autonomous_transaction; I did that, and that solved the problem therePRAGMA AUTONOMOUS_TRANSACTION "bends" the restriction against SQL against base table.
    It is the equivalent to tap dancing across a mine field.
    You might get the desired results most of the time or you might get a tasty surprise when you least expect it.
    What happens to your application in the future, if/when the UPDATE has a ROLLBACK issued & PRAGMA AUTONOMOUS_TRANSACTION has successfully completed?
    Inquiring minds would like to know the answer.

  • After Insert Trigger - IF-THEN-ELSE

    Is it possible to put an if-then-else statement in an after insert trigger with an update to a second table?
    CREATE OR REPLACE trigger bev_trg
    after insert
    on bev
    for each row
    DECLARE
    MEINS VARCHAR2(3);
    SPART VARCHAR2(2);
    FKIMG NUMBER(22);
    SHKZG CHAR(1);
    BEGIN
    insert into bev2
    (vbeln,
    posnr)
    values
    (:new.vbeln,
    :new.posnr
    IF FKIMG = '10' and MEINS = 'EA'
    THEN
         update bev2 set bwsie = (fkimg * '12.17') ;
    ELSIF
    FKIMG = '12' and MEINS = 'EA'
    THEN
         update bev2 set bwsie = (fkimg * '19.02');
    ELSIF
    SHKZG = 'X'
    THEN
         update bev2 set bwsie = (fkimg * '-1');
    ELSE
         update bev2 set bwsie = '0' ;
    END IF;
    update bev2 set bwfkimg = (fkimg * '-1') where SHKZG = 'X';
    end;
    This does not do the updates.
    Thanks
    Bev

    My original problem is this: I need to create a table
    derived from data in another table
    and change it to be the conditional data in the update statements.
    create table bev(
    VBELN VARCHAR2(10),
    POSNR VARCHAR2(6),
    MEINS VARCHAR2(3),
    SPART VARCHAR2(2),
    FKIMG NUMBER(22),
    SHKZG CHAR(1),
    BWSIE NUMBER(9,2),
    BWFKIMG NUMBER(22)
    update bev set bwsie = (fkimg * '12.17') where SPART = '10' and meins = 'EA' ;
    update bev set bwsie = (fkimg * '19.02') where SPART = '12' and meins = 'EA';
    update bev set bwsie = (fkimg * '27.39') where SPART = '15' and meins = 'EA';
    update bev set bwsie = (fkimg * '48.69') where SPART = '20' and meins = 'EA';
    update bev set bwsie = (fkimg * '109.56') where SPART = '30' and meins = 'EA';
    update bev set bwsie = '0' where meins = 'EA' and SPART not in('10','12','15','20','30');
    update bev set bwsie = (fkimg * '-1') where SHKZG = 'X';
    update bev set bwfkimg = (fkimg * '-1') where SHKZG = 'X';
    This did not produce the required results so I thought I would try
    creating a second table
    and using a trigger with if-then-else to update it.
    Can't use the trigger on the
    original table because it mutates.
    create table bev2(
    VBELN VARCHAR2(10),
    POSNR VARCHAR2(6),
    BWSIE NUMBER(9,2),
    BWFKIMG NUMBER(22)
    insert into bev select vbeln, posnr, meins, spart, fkimg , shkzg, '', ''
    from [email protected]
    where vbeln = '0090043834' and posnr = '000011'
    insert into bev select vbeln, posnr, meins, spart, fkimg , shkzg, '', ''
    from [email protected]
    where vbeln = '0090043833' and posnr = '000011'
    CREATE OR REPLACE trigger bev_trg
    after insert
    on bev
    for each row
    DECLARE
    MEINS VARCHAR2(3);
    SPART VARCHAR2(2);
    FKIMG NUMBER(22);
    BEGIN
    insert into bev2
    (vbeln,
    posnr,
    fkimg
    values
    (:new.vbeln,
    :new.posnr,
    :new.fkimg
    IF :new.FKIMG = '10' and :new.MEINS = 'EA'
    THEN
    update bev2 set bwsie = (:new.fkimg * '12.17') ;
    ELSIF
    :new.FKIMG = '12' and :new.MEINS = 'EA'
    THEN
    update bev2 set bwsie = (:new.fkimg * '19.02');
    ELSIF
    :new.FKIMG = '15' and :new.MEINS = 'EA'
    THEN
    update bev2 set bwsie = (:new.fkimg * '27.39');
    ELSIF
    :new.FKIMG = '20' and :new.MEINS = 'EA'
    THEN
    update bev2 set bwsie = (:new.fkimg * '48.69');
    ELSIF
    :new.FKIMG = '30' and :new.MEINS = 'EA'
    THEN
    update bev2 set bwsie = (:new.fkimg * '109.56');
    ELSIF
    SHKZG = 'X'
    THEN
    update bev2 set bwsie = (:new.fkimg * '-1');
    ELSE
    update bev2 set bwsie = '0' ;
    END IF;
    update bev2 set bwfkimg = (:new.fkimg * '-1') where SHKZG = 'X';
    end;

  • After insert trigger issue

    Hi All,
    Can I have an after insert trigger on a table wherein the execution is also on the same table?
    It's like 10 columns in the table A.
    During a new row insertion, except one specific column(say 'J'), remaining all getting data.
    Now 'after insert', need to update the data of the column J based on one inserted value for column say ID.
    Code goes like below:
    CREATE OR REPLACE TRIGGER UPDATE_J
    AFTER INSERT ON A REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    begin
    if :new.ID = 'N%' then
         :new.J:= 'N';
    else
         :new.J:= 'M';
    end if;
    end;
    Below is the error when I tried to execute that.
    ORA-04091: table string.string is mutating, trigger/function may not see it
    Cause: A trigger (or a user defined plsql function that is referenced in this statement) attempted to look at (or modify) a table that was in the middle of being modified by the statement which fired it.
    Action: Rewrite the trigger (or function) so it does not read that table.
    Any idea to resolve?
    Regards,
    Seetharaman.

    Hi,
    The docs say
    Restrictions on AFTER
          An AFTER row trigger or AFTER row section of a compound trigger can only read but not write into the :OLD or :NEW fields. When faced with problems like this, it is always a good thing to consult the documentation.
    Regards
    Peter

  • Before or After insert trigger on HR_API_TRANSACTION_VALUES

    I am on the termination page of SSHR and after entering the details when clcked on 'Next' the validations built in before / after insert trigger of HR_API_TRANSACTION_VALUES does not retrieve the data and the error 'No data found' is displayed.
    We do not have AME approval. When clicked on 'Next' it goes to the review page. When I do a select on the HR_API_TRANSACTION_VALUES the data do exists but the validation does not work.
    We have Oracle HRMS 11i with database as 11g.
    Please give a resolution at the earliest.

    you can use
    hr_transaction_api.set_varchar2_value
    or
    hr_transaction_api.set_number_value
    based on what type of value that you want to update

  • Error in after insert trigger

    Hello all,
    I have a question about after insert trigger. Will be new row inserted and commited if after insert trigger returns error? Thank you.
    regards,
    Miha

    What is the error that u r facing?
    there could multiple reasons for that. Basically, u can't put commit in the trigger (unless it is an autonomous transaction). Share the pseudo-code of u r triiger, so that , problem can be identified.
    Cheers,
    Ram Kanala

  • Updating statistics after insert

    Is it possible, without creating a custom post-map process, to update statistics after inserting rows into a table. I've tried setting different parameters within OWB to no avail.
    Please respond only if you have actually succeeded in updating statistics without writing code. I've already read the docs and experimented.
    Thanks.
    Garrett

    Hi,
    why do you think so? The analyze configuration
    results in a procedure which calls
    WB_RT_MAPAUDIT_UTIL_INVOKER for each target table
    which then calls the DBMS_STATS-Package? What is
    misssing for the CBO? I'm a little bit confused?!
    Regards,
    DetlefThanks for the info. I'm a little confused. I thought that I had the analyze table box checked in the configuration and statistics were not updated. However, when I looked again, it was not checked. My error. Ran another test and statistics were updated. Sorry for the confusion.
    G.

  • After insert trigger with :NEW.ROWID

    Hi All,
    I am using a After insert trigger to generate history record as following:
    CREATE TABLE TB_TEST (classID number(3), classNm varchar2(12));
    CREATE TABLE TB_HIST_TEST (hist_dttm timestamp(6), classID number(3), classNm varchar2(12));
    CREATE or REPLACE TRIGGER air_test AFTER INSERT ON tb_test FOR EACH ROW
    BEGIN PK_SRVC.CRT_NewRec('TB_TEST', 'TB_HIST_TEST', :new.ROWID); END:
    In PK_SRVC package, I use the following statment to create new record in TB_HIST_TABLE:
         Insert into tb_hist_test (hist_dttm, classID, classNm)
         values (select systimestamp, classID, classNm from tb_test where rowid = ROWID )
    The trigger DOES fire when a new row is inserted into TB_TEST. However there is no record inserted into TB_HIST_TEST. Any suggestion?
    Thanks,

    The PK_SRVC.CRT_NewRec is a generic service package that can be shared by many tables. It uses dynamic SQL to get all the collumns for different tables based on USER_TAB_COLUMNS.  The following is the code of this package:
    PROCEDURE CRT_NewRec ( p_TableName IN VARCHAR2, p_AudTableName IN VARCHAR2, p_RowID)
    IS
           TYPE TabCol_RecTyp IS RECORD (COLUMN_NAME VARCHAR2(30), COLUMN_ID NUMBER);
           TYPE TabCol_CurTyp IS REF CURSOR;
            c_TabCol TabCol_CurTyp;
            rc_TabCol TabCol_RecTyp;
            v_Sql_TabCol VARCHAR2(1000);
            v_ColNames VARCHAR2(1000);
            v_Sql VARCHAR2(1000);
            PRAGMA AUTONOMOUSE_TRANSCATION;
    BEGIN
            v_SQL_TabCol := ' SELECT column_name, column_id FROM USER_TAB_COLUMNS'
                                      ||  ' WHERE table_name = ' || CHR(39) || p_TableName || CHR(39)
                                      || '  ORDER BY column_id';
            v_ColNames := NULL;
            OPEN c_TabCol FOR v_Sql_TabCol;
            Loop
                   FETCH c_TabCol INTO rc_TabCol; Exit WHEN c_TabCol%NOTFOUND:
                   v_ColNames := v_ColNames || ',' || rc_TabCol.COLUMN_NAME;
            End Loop;
            CLOSE c_TabCol;
            v_Sql := 'INSERT INTO ' || p_AudTableName || '(HIST_DTTM, ' || v_ColNames || ' )'  
                      || ' SELECT systimestamp, ' || v_ColNames || ' FROM ' || p_TableName
                      || ' WHEN ROWID = chartorowid(' || CHR(39) || p_RowId || CHR(39) || ')';
             EXECUTE IMMEDIATE v_Sql;
             COMMIT;
    END;    
    (charmingholidays-yyz)

  • After insert trigger

    Dears,
    In after insert trigger implementation if the base table failed due to some errors.
    Is it possible to still have records inserted in the log table inside the trigger
    Thanks
    Janani.C

    What you want is to write log records to a table, regardless of whether the transaction they're logging fails. This would make sense for inevstigating errors,e tc. This is the only time when it is acceptable to use autonomous transactions.
    Encapsulate your logguing code in a separate procedure which has the {font:courier new}PRAGMA autonomous_transaction{font} in its declaration, and include a commit. Such a procedure works in its own separate tranasction - a separate session in fact - and write the log record without affecting the broader transaction. [url http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/sqloperations.htm#sthref1515]Find out more.
    Cheers, APC
    P.S. I agree with Hoek that you should investigate teh LOG ERRORS INTO functionality, as it can be very useful, especially with bulk processes. However, it can only store information directly relating to the rejected records, which might not be sufficient for your purposes.

  • Updating row after insert that causes trigger

    Hi,
    I have a table which one of the columns is a sequence number which each time a new row is written I want to automatically write to this sequence column the latest number (which is maintained using an Oracle sequence). I decided to use a trigger which works great:
    CREATE OR REPLACE TRIGGER pre_insert_trg before insert ON INCOMING
    for each row
    BEGIN
    SELECT INCOMING_SEQ.NEXTVAL
    INTO :new.SEQ
    FROM DUAL;
    END;
    The problem is I have many multi-threaded processes writing to this table and the sequence number gets allocated before the row is committed which means although thread 1 may write first it may commit after thread 2 which has a later sequence number which has the result that sequence number 2 may be shown before 1. The problem is much larger when dealing with many threads with 100's of messages a second and so I would prefer the seq to be added AFTER the insert (once committed), e.g.
    CREATE OR REPLACE TRIGGER post_insert_trg after insert ON INCOMING
    for each row
    BEGIN
    SELECT INCOMING_SEQ.NEXTVAL
    INTO :new.SEQ
    FROM DUAL;
    END;
    Trying to create this trigger results in a "ORA-04084: cannot change NEW values for this trigger type". Is there a way to update a column for the row which caused the trigger? If I try and remove the :new. I then get errors when inserting about mutating table (which I understand the DML locking but need a way round)
    Many thanks,
    John

    Off hand I think the only way you can do what you say you want to do is to replace the sequence with a code table. A transaction locks the code table, gets the next value from it and unlocks the code table at the end of the transaction. This ensures that the sequence number is always assigned in transaction completion order (or rather the transactions always complete in sequence assigned order). It is basically what java does with its synchronize statement.
    The only drawback with this approach is that it completely shags the performance of the sort of multi-threaded environment you've just described. :P
    So you need to decide what's more important: having stuff inserted into a queue in sequence order or having a multi-threaded system running quickly. I really don't see how you can acheive what you're attempting in a genuinely concurrent environment; you'll have to introduce an artificial serialism (ie bottleneck) somewhere.
    If you do crack this please tell me how: I would be interested in ordering multiple AQs in the fashion you described.
    Cheers, APC

  • After Insert Trigger Not Working

    Hi All,
    I am not a guru in writing triggers.
    I am inserting new records in a Table FA_BOOKS by application and this inserts records in FA_ADDITIONS_B. This is a vanilla process.
    i have written a trigger on FA_ADDITIONS_B, and i want to update the cost from the fa_books to fa_additions_b column attribute21
    The trigger i have written is After insert on FA_ADDITIONS_B and i try to select cost from the fa_books for the :new.asset_id.
    SELECT COST
    INTO v_cost
    FROM FA_BOOKS
    WHERE ASSET_ID = :NEW.ASSET_ID;
    this is always returning no_data_found exception and i do not understand how to update the attribute21 in FA_ADDITIONS_B
    Here is a sample of my trigger.
    CREATE OR REPLACE TRIGGER update_attribute21_new_asset_1
    after INSERT ON fa_ADDITIONS_B
    FOR EACH ROW
    DECLARE
    V_COST NUMBER;
    BEGIN
    SELECT COST
    INTO v_cost
    FROM FA_BOOKS
    WHERE ASSET_ID = :NEW.ASSET_ID;
    update fa_ADDITIONS_B
    set attribute21 = v_cost
    where ASSET_ID = :NEW.ASSET_ID;
    END;
    Any help on this will be appreciated.
    TX in advance.
    Regards,

    I still haven't understood the reason why you can't transfer the COST information from FA_BOOKS to FA_ADDITIONS_B in the initial trigger on FA_BOOKS that populates FA_ADDITIONS_B. Or how is the population of FA_ADDITIONS_B accomplished? Is it part of the application code?
    Regarding the NO_DATA_FOUND issue:
    Is it ensured that populating the FA_ADDITIONS_B table is done in the same transaction as the FA_BOOKS inserts or that the FA_BOOKS transaction is committed?
    Why do you need that additional trigger?
    My assumption is that you're in a trigger "chain" - if I get your approach correctly - you're basically attempting to query FA_BOOKS in a trigger on FA_ADDITIONS_B that in turn has been triggered by a trigger on FA_BOOKS which gets us back to the "mutating" trigger issue. You can't read a table that is currently in the process of being modified.
    Or even worse: The (potential) trigger on FA_BOOKS that populates FA_ADDITIONS_B uses "autonomous transaction" and therefore the trigger on FA_ADDITIONS_B can't see the changes of the original transaction.
    As already mentioned: Be very careful with "autonomous transactions" in general. There are only a few cases where these are actually useful (e.g. logging purposes), but Tom Kyte has written numerous articles why triggers and in particular autonomous transactions are mostly evil.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Compilation error in  AFTER INSERT TRIGGER

    I am getting a compilation error with this code. How can I make this work?
    CREATE OR REPLACE TRIGGER LIMS.u_tu_background_priority
        AFTER INSERT
        ON BACKGROUND
         FOR EACH ROW
    BEGIN
        IF instr(:new.parameter,'S') = 1 THEN
            UPDATE lims.background
            SET priority = 3
              WHERE background_id = :new.background_id
        END IF ;       
    END ;
    /

    TABLE background
    Name                                      Null?    Type                       
    BACKGROUND_ID                             NOT NULL NUMBER(16)                 
    PRIORITY                                           NUMBER                     
    SESSION_ID                                         NUMBER(16)                 
    SCHEDULE_ID                                        NUMBER(16)                 
    WORKSTATION_ID                                     NUMBER(16)                 
    WORKSTATION_GROUP_ID                               NUMBER(16)                 
    PARAMETER                                          VARCHAR2(4000)             
    ACTIVE                                             CHAR(1)                    
    BACKGROUND_TASK_TYPE_ID                            NUMBER(16)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • After insert trigger error

    Hi,
    i have created an Trigger After Insert According to me, It's correct But it show me Error Can Not Insert Null in to code.
    CREATE OR REPLACE TRIGGER  "AFT_INS_CRM_CUSTOMER_CONTACTS"
      AFTER INSERT ON FH_TAPROD.CRM_SALES_CUSTOMER_CONTACTS
    FOR EACH ROW
    DECLARE
    custo_id NUMBER;
    var_code varchar2(8);
    cont_code varchar2(5);
    BEGIN
    SELECT CUSTOMER_ID INTO custo_id FROM CRM_SALES_CUSTOMER_CONTACTS WHERE ID =:NEW.ID;
      select CODE into var_code from VENDOR_CUSTOMER_MAS where CRM_CUST_ID=custo_id ;
      SELECT LPAD ( NVL(MAX(CONTACT_CODE), 0)+ 1, 5, '0') into cont_code FROM vendor_customer_contact
      insert into VENDOR_CUSTOMER_CONTACT(SBU_CODE ,CODE,CONTACT_CODE, CONTACT_NAME ,PHONE_NO1 ,MOBILE_NO ,EMAIL, ADDRESS1,CUST_ID,UPLOAD_CRM)
       values('0002',var_code,cont_code,:NEW.CONTACT_NAME,:NEW.CONTACT_PHONE,:NEW.CONTACT_CELL,:NEW.CONTACT_EMAIL,:NEW.CONTACT_ADDRESS,custo_id,'CRM');
    END;
    CREATE TABLE  "CRM_SALES_CUSTOMER_CONTACTS"
       (     "ID" NUMBER,
         "CUSTOMER_ID" NUMBER,
         "CONTACT_NAME" VARCHAR2(255),
         "CONTACT_EMAIL" VARCHAR2(255),
         "CONTACT_PHONE" VARCHAR2(255),
         "CONTACT_CELL" VARCHAR2(255),
         "CONTACT_ADDRESS" VARCHAR2(4000),
          PRIMARY KEY ("ID") ENABLE
    INSERT INTO CRM_SALES_CUSTOMER_CONTACTS VALUES (204414862717175278810736770347803084847, 204232590877603599356756434170666837075, 'SANJAY',    '[email protected]', 1246456, 57152357,'Near Post Office');
    CREATE OR REPLACE TRIGGER  "BIU_CRM_SALES_CUST_CONTACTS"
    BEFORE INSERT OR UPDATE ON CRM_SALES_CUSTOMER_CONTACTS
        FOR EACH ROW
    begin
        if inserting and :new.id is null then
            select to_number(sys_guid(),'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') into :new.id from dual;
        end if;
        if inserting then
            :new.created_by := nvl(v('APP_USER'),USER);
            :new.created_on := sysdate;
        end if;
        if updating then
            :new.updated_by := nvl(v('APP_USER'),USER);
            :new.updated_on := sysdate;
        end if;
    end;My After Insert TAble
    CREATE TABLE  "VENDOR_CUSTOMER_CONTACT"
       (     "SBU_CODE" VARCHAR2(4) NOT NULL ENABLE,
         "CODE" VARCHAR2(8) NOT NULL ENABLE,
         "CONTACT_CODE" VARCHAR2(5) NOT NULL ENABLE,
         "CONTACT_NAME" VARCHAR2(1000) NOT NULL ENABLE,
         "PHONE_NO1" VARCHAR2(100),
         "MOBILE_NO" VARCHAR2(25),
         "EMAIL" VARCHAR2(1000),
         "ADDRESS1" VARCHAR2(4000),
         "CUST_ID" NUMBER,
         "UPLOAD_CRM" VARCHAR2(10),
          CONSTRAINT "VCV_PK" PRIMARY KEY ("SBU_CODE", "CODE", "CONTACT_CODE") ENABLE
    ORA-01400: cannot insert NULL into ("FH_TAPROD"."VENDOR_CUSTOMER_CONTACT"."CODE") ORA-06512: at "FH_TAPROD.AFT_INS_CRM_CUSTOMER_CONTACTS", line 30 ORA-04088: error during execution of trigger 'FH_TAPROD.AFT_INS_CRM_CUSTOMER_CONTACTS'How to resolve it.
    Thanks
    Edited by: 805629 on Jan 14, 2011 1:26 AM

    This is your trigger
    CREATE OR REPLACE TRIGGER  "AFT_INS_CRM_CUSTOMER_CONTACTS"
      AFTER INSERT ON FH_TAPROD.CRM_SALES_CUSTOMER_CONTACTS
    FOR EACH ROW
    DECLARE
    custo_id NUMBER;
    var_code varchar2(8);
    cont_code varchar2(5);
    BEGIN
    SELECT CUSTOMER_ID INTO custo_id FROM CRM_SALES_CUSTOMER_CONTACTS WHERE ID =:NEW.ID;
      select CODE into var_code from VENDOR_CUSTOMER_MAS where CRM_CUST_ID=custo_id ;
      SELECT LPAD ( NVL(MAX(CONTACT_CODE), 0)+ 1, 5, '0') into cont_code FROM vendor_customer_contact;
      insert into VENDOR_CUSTOMER_CONTACT(SBU_CODE ,CODE,CONTACT_CODE, CONTACT_NAME ,PHONE_NO1 ,MOBILE_NO ,EMAIL, ADDRESS1,CUST_ID,UPLOAD_CRM) values('0002',var_code,cont_code,:NEW.CONTACT_NAME,:NEW.CONTACT_PHONE,:NEW.CONTACT_CELL,:NEW.CONTACT_EMAIL,:NEW.CONTACT_ADDRESS,custo_id,'CRM');
    END;This is the insert who fire it
    INSERT INTO CRM_SALES_CUSTOMER_CONTACTS VALUES (204414862717175278810736770347803084847, 204232590877603599356756434170666837075, 'SANJAY',    '[email protected]', 1246456, 57152357,'Near Post Office');Then the trigger execute
    SELECT CUSTOMER_ID FROM CRM_SALES_CUSTOMER_CONTACTS WHERE ID =204232590877603599356756434170666837075;
    select CODE from VENDOR_CUSTOMER_MAS where CRM_CUST_ID=<result of previous query>;
    SELECT LPAD ( NVL(MAX(CONTACT_CODE), 0)+ 1, 5, '0') FROM vendor_customer_contact;
    Insert ...And fail.
    Execute the select in your sqlplus one by one and post result.

Maybe you are looking for