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)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • 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

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

  • 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

  • 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

    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.

  • 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

  • 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

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

  • Error in post insert trigger

    Hi to all,
    In a table I have a field id that must be valorized from sequence.
    It is possible valorize this sequence after the insert ?
    I have tried to create a trigger like this:
    CREATE OR REPLACE TRIGGER MYSCHEMA.POST_USERACCOUNTS_INSERT
    AFTER INSERT
    ON MYSCHEMA.USERACCOUNTS
    REFERENCING NEW AS New OLD AS Old
    FOR EACH ROW
    DECLARE
    tmpVar NUMBER;
    BEGIN
       tmpVar := 0;
       SELECT SEQ_USERACCOUNTS_ID.NEXTVAL INTO tmpVar FROM dual;
       :NEW.USERS_ID := tmpVar;
       :NEW.DATECREATION := SYSDATE;
       EXCEPTION
         WHEN OTHERS THEN
           -- Consider logging the error and then re-raise
           RAISE;
    END POST_USERACCOUNTS_INSERT;But the creation abort with this error:
    ORA-04084: cannot change NEW values for this trigger type
    How can resolve this problem ?
    Thank You for help.
    Greetings...
    Gaetano

    Cause
    New trigger variables can only be changed in before row insert or update triggers.
    Action
    Change the trigger type or remove the variable reference.

  • Errors with post-insert trigger

    I had a POST-INSERT TRIGGER here.but i encountered some problems.can someone help me with the errors?
    begin
         insert into user_acct
         userid_n, user_m, coy_c, contact_n, emp_n,
         work_loc_c, curr_passwd_t, prt_f, indv_pc_f, pc_deploy_c,      
         ext_email_addr_t, other_na_sys_t, status_c, status_rmk_t, upd_d)
         values
         (:user_acct.userid_n, :user_acct.user_m, :user_acct.coy_c, :user_acct.contact_n, :user_acct.emp_n,
         :user_acct.work_loc_c, :user_acct.curr_passwd_t, :user_acct.prt_f, :user_acct.indv_pc_f, :user_acct.pc_deploy_c,                
         :user_acct.ext_email_addr_t, :user_acct.other_na_sys_t, :user_acct.status_c, :user_acct.status_rmk_t,                
         :user_acct.upd_d);
         exception
              when others then
                   clear_message;
                   Message('Insertion of Applicant Particulars failed');
                   SYNCHRONIZE;
                   RAISE Form_Trigger_failure;
    end;
    begin
    insert into user_acct_na_detl
         na_sys_c)
         values
         (:na_sys_cd.na_sys_c);
         exception
              when others then
                   clear_message;
                   Message('Insertion of Non-Application failed');
                   SYNCHRONIZE;
                   RAISE Form_Trigger_failure;
    end;
              when others then
                   null;      
    end;     
    the error:
    Error 103 at line 31, column 3
    Encountered the symbol 'WHEN' when expecting one if the following:
    begin declare end exception exit for goto if loop mod null
    pragma raise return select update while <an identifier>
    <a double-quoted delimited-identifier><a bind variable><<
    close current delete fetch lock insert open rollback
    savepoint set sql commit<a single-quoted SQL string>
    The symbol "exception"was substituted for "WHEN" to continue
    Error 103 at line 2, column 1
    Encountered the symbol "END"

    i delete the "END" already but when i compile again, i encountered some error again.
    Error 370 at line 27, column
    OTHERS handler must be last among the exception handlers of a block
    Error 0 at line 1, column 1
    Statement ignored

  • Can't able to use :NEW in after insert trigger

    When i am trying to assign value to an element of the NEW pseudo record, its giving error like :new pseudo record can't be used in this type of trigger.
    What exactly i've done is given below
    create or replace triger tri_name
    after insert
    on tab_name
    for each row
    begin
    if :new.x='123' then
    :new.y:=null;
    end if;
    end tri_name;
    Thanks & Regards
    --DKar                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    from oracle documentation...
    Old and new values are available in both BEFORE and AFTER row triggers. A new column value can be assigned in a BEFORE row trigger, but not in an AFTER row trigger (because the triggering statement takes effect before an AFTER row trigger is fired). If a BEFORE row trigger changes the value of new.column, then an AFTER row trigger fired by the same statement sees the change assigned by the BEFORE row trigger.
    for more details read the documentation

Maybe you are looking for