Insert trigger with if condition

Hi.
I am new sql programming and I am trying to write a insert trigger.
I have created an insert-trigger that inserts into another table(p_person) whenever the trigger table (p_personmds) gets insterted:
CREATE OR REPLACE TRIGGER INSERT_P_PERSON_TG
AFTER INSERT ON P_PERSONMDS
FOR EACH ROW
BEGIN
insert into P_PERSON (person,person_id,person_name,email_address,disabled)
values (seq_p_person.nextval,:new.person_id,:new.person_name,:new.email_address,:new.disabled);
END INSERT_P_PERSON_TG;
After testing the trigger I discovered that I need to add some checking to the trigger:
If person_id already exists in the p_person table I need to just update the 'DISABLED' column and set it to 'null' value.
So I tried modifying the trigger:
CREATE OR REPLACE TRIGGER TESTMDS.INSERT_P_PERSON_TG
AFTER INSERT ON TESTMDS.P_PERSONMDS
FOR EACH ROW
BEGIN
IF :new.disabled is not null
THEN
update p_person set disabled=NULL where person_id=:old.person_id;
ELSE
insert into P_PERSON (person,person_id,person_name,email_address,disabled)
values (seq_p_person.nextval,:new.person_id,:new.person_name,:new.email_address,:new.disabled);
END IF;
END INSERT_P_PERSON_TG;
Hovewer the triggers seems to ignore the first if update condition and only inserts another row with mulitiple values.
Anyone know what I am doeing wrong here?

user12064835 wrote:
so if I use: 'IF :OLD.Disabled is not NULL then' ,
will :OLD:Disabled represent the p_person table or do I have to come up with something new?if you use :old.Disable, it will run always the ELSE-block.
you should write your block as same thing like follows:
IF :new.disabled is not null THEN
  update p_person set disabled=NULL where person_id=:old.person_id;
  IF SQL%ROWCOUNT = 0 THEN --this block will be executed if there was no row updated in table p_person
    insert into P_PERSON (person,person_id,person_name,email_address,disabled)
    values (seq_p_person.nextval,:new.person_id,:new.person_name,:new.email_address,:new.disabled);
  END IF;
ELSE
  insert into P_PERSON (person,person_id,person_name,email_address,disabled)
  values (seq_p_person.nextval,:new.person_id,:new.person_name,:new.email_address,:new.disabled);
END IF;but
user12064835 wrote:
if DISABLED column is not null in p_person table I want to insert a null value in the DISABLED column in p_person
where the person_id that gets inserted in p_personmds table = person_id in p_person table.means
  update p_person set disabled=NULL where person_id=:old.person_id AND disabled is not NULL; 

Similar Messages

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

  • INSERT TRIGGER WITH DATE

    hi,
    This may be a very basic doubt.please help me.
    i m creating the dynamic table every month to maintain the particular month data seperately .when the records are getting inserted in the table,trigger will automatically insert the records in the dynamic table. In the ACTN_DATE column, only date alone(without timestamp) getting inserted in the dynamic table from main table. so by default ,00:00:00 is getting appended with date instead of actual timestamp present in the main table. tried select to_date(to_char(:new.ACTN_DATE,'YYYY-MM-DD HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS') INTO v_temp_actn_date from dual; then in the insert query ,i tried to insert the temp. variable v_temp_actn_date. but only date alone getting inserted in the dynamic table . In main table and dyanmic table datatype for date column is date .
    actn_date value in main table 30-jun-2012 12:50:32 but actn_date value in the dynamic table is 30-jun-2012 00:00:00 . don't know why timestamp value is not present in the date field. please help me solve this issue .Thanks.

    Welcome to the forum!
    Whenever you post please provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
    I don't understand how you data is getting inserted into each of the tables.
    >
    when the records are getting inserted in the table,trigger will automatically insert the records in the dynamic table.
    >
    What exactly is the trigger doing? What kind of trigger is it? What table is it on? Is the trigger inserting data into another table? Post the trigger code.
    Please show the sample data from each table and the query that is being used to SELECT data from the one table and INSERT it into the main table.

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

  • 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

  • Pre-Insert Trigger not firing

    Hi,
    I am using Oracle 10G DS with Oracle 11G XE. I tried PRE-INSERT Trigger with the Code given by Mr Hamid. However, its not working. Though, the WHEN-NEW-ITEM-INSTANCE works fine, I wish to use PRE-INSERT Trigger only.
    Can you please help me.
    My Code is shown below
    BEGIN
    SELECT asset_id_seq.nextval INTO :r_it_blk.asset_id
    FROM dual;
    END;
    Thanks in advance
    Ramesh

    Hi Hamid,
    Thank you very much for your reply.
    I tried at Block Level itself. Further, I also tried the below Code with Cursor (Block Level). Unfortunately, it is also not working. Even the Error Message is also not displayed. The User has full privileges.
    DECLARE
         CURSOR next_id IS SELECT asset_id_seq.NEXTVAL FROM dual;
    BEGIN
         OPEN next_id;
         FETCH next_id INTO :r_it_blk.asset_id;
         CLOSE next_id;
         IF :r_it_blk.asset_id IS NULL THEN
         Message('Error Generating Next Asset ID');
         RAISE Form_Trigger_Failure;
         END IF;
    END;
    Regards
    Ramesh

  • Trigger with Condition problem - insert only when not exists

    Hello experts!
    I have a problem with a trigger I'm trying to create. It compiles but I receive an error message when the trigger fires.
    The scenario is as follows:
    I have a table TBL_PUNKTDATEN. Whenever the status for a record in that table is changed to 3 or 4 I need the trigger to insert a dataset into my target table (TBL_ARBEIT_ZU_GEBIET).
    However, the trigger must only insert data when there's no existing record in the target table. The condition that specifies whether there is a dataset or not, is the field LNG_GEBIET, which exists in the source as well as in the target table. Hence, for each LNG_GEBIET there can be only one dataset in the target table!
    I created a trigger using the following code. However it doesn't work.
    Maybe you'll see what I want to achieve when having a look at my code.
    Can you please help me out on this one?
    Thanks a lot!
    Sebastian
    create or replace
    TRIGGER set_status_arbeit_zu_gebiet AFTER
      UPDATE ON TBL_PUNKTDATEN FOR EACH ROW WHEN(new.INT_STATUS=3 or new.INT_STATUS=4)
    declare
        cursor c is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET=:new.LNG_GEBIET;
        x number;
    begin
        open c;
        fetch c into x;
        if c%NOTFOUND  then 
        INSERT INTO TBL_ARBEIT_ZU_GEBIET
            LNG_GEBIET,
              LNG_ARBEITSSCHRITT,
              PNUM,
              INT_BEARBEITER,
              DATE_DATUM,
              GEPL_DATUM
            VALUES
            (:new.LNG_GEBIET,
             52,
             1114,
             895,
             sysdate,
             to_date('01.01.1990', 'DD.MM.YYYY')
        end if;
    end;Well, on the first insert the code works properly and inserts the recordset as expected. However, if there is an existing recordset where :new.LNG_GEBIET matches LNG_Gebiet in my target table, I receive the ORA-06502 error!
    Maybe that spcifies it a little bit???
    Hope you can help me!
    Thank you!
    Edited by: skahlert on 23.09.2009 10:26
    Edited by: skahlert on 23.09.2009 10:28

    Thank you very much Peter G!
    That %Rowtype mod did the trick! Great solution! Thanks! The trigger works principally if there wasn't the fact that it fires also when the status of one individual record is 3 or 4.
    I need it to fire only when all records with the same attribute LNG_GEBIET (by the way, you guess was right - it's not a number) are of status 3 or 4.
    Is it possible to use the cursor function for the trigger's when condition?
    Such as:
    declare
        cursor c3 is select COUNT(*) from TBL_PUNKTDATEN where LNG_GEBIET=:new.LNG_GEBIET;and
    declare
        cursor c4 is select COUNT(*) from TBL_PUNKTDATEN where INT_STATUS = 3 and  LNG_GEBIET=:new.LNG_GEBIET or INT_STATUS = 4 and  LNG_GEBIET=:new.LNG_GEBIET;
      And then subsequently somehow compare the results of both cursors?
    ... WHEN c3=c4
    declare
        cursor c2 is select LNG_GEBIET from TBL_ARBEIT_ZU_GEBIET where PNUM = 1114 and LNG_GEBIET=:new.LNG_GEBIET;
        v_c2  c2%ROWTYPE;
    begin
    open c2;
    fetch c2 into v_c2;
    if c2%notfound then
            INSERT INTO TBL_ARBEIT_ZU_GEBIET
            LNG_GEBIET,
              LNG_ARBEITSSCHRITT,
              PNUM,
              INT_BEARBEITER,
              DATE_DATUM,
              GEPL_DATUM
            VALUES
            (:new.LNG_GEBIET,
             52,
             1114,
             895,
             sysdate,
             to_date('01.01.1990', 'DD.MM.YYYY')
            end if;
            close c2;
    end;Please excuse me if the attempt is simply stupid!
    Sebastian
    Edited by: skahlert on 23.09.2009 15:36
    I just saw your reply Max! Thank you! Now I understand far better! Seems to be a successful day! I'm learning a lot! Will also test that method!
    If we could find a solution to the problem I described above it would make it a perfect day! I'm continously trying different attempts to have the trigger only fire when all records are 3 or 4.
    Not that you think I'm just waiting for your answers! That's not the case!
    Thank you all!
    Edited by: skahlert on 23.09.2009 17:30

  • "instead of" trigger on a view with a condition

    I'm trying to create an instead-of trigger on a view but I want it all such that:
    1. It fires only for a certain condition.
    2. When the condition isn't met, I want the normal DML on the view to continue as it normally would.
    3. I want to avoid writing as much manual DML code as possible for long-term maintainability.
    My first attempt is like this:
    create or replace trigger PROPOSAL_PARTS_V_IRU
      instead of update on proposal_parts_v
      for each row
      WHEN :old.PART_MASTER_ID <> :new.PART_MASTER_ID
    BEGIN
      do_stuff_for_part_master_change;
    END;So when the OLD and NEW PART_MASTER_IDs have changed, I want special processing. Else, I want it to do whatever it normally does (let the view get updated and the database will manage the update of the underlying table).
    When compiling that I get "ORA-25004: WHEN clause is not allowed in INSTEAD OF triggers".
    OK I will accept that even though I want it to work.
    So my next attempt could be:
    create or replace trigger PROPOSAL_PARTS_V_IRU
      instead of update on proposal_parts_v
      for each row
    BEGIN
      IF :old.PART_MASTER_ID <> :new.PART_MASTER_ID THEN
        do_stuff_for_part_master_change;
      ELSE
        UPDATE proposal_parts -- Manually update the underlying table with manually-written DML but I hate having to do this in case the view or table columns change.
        SET...
        WHERE...
      END;So my question is...is there any syntax to do something like this?
    create or replace trigger PROPOSAL_PARTS_V_IRU
      instead of update on proposal_parts_v
      for each row
    BEGIN
      IF :old.PART_MASTER_ID <> :new.PART_MASTER_ID THEN
        do_stuff_for_part_master_change;
      ELSE
        update_row;
      END;...where "update_row" is some sort of built-in command that tells oracle to continue with the current update as if the trigger never existed.
    Back in the day I seem to remember that Oracle Forms had a trigger and syntax like this where you could intercept a DML and if under certain conditions it wasn't true, you could say "update_row" (or maybe it was "update_record?...whatever) and it meant "continue with update as if this instead-of trigger never existed".
    Is anything available like that for the DB now? I know in older versions no, but we are now on 11g...anything new come out like this?
    Otherwise I have to manually write an update statement and I'd rather not if I don't need to.
    Thanks!

    riedelme wrote:
    gti_matt wrote:
    I'm trying to create an instead-of trigger on a view but I want it all such that:
    1. It fires only for a certain condition.You can use IF Logic inside a trigger to do or not do anything. As long as it is a condition you can check you can code IF logic around it
    2. When the condition isn't met, I want the normal DML on the view to continue as it normally would.You will have to code all of your logic in the INSTEAD of trigger. The whole purpose of the INSTEAD OF trigger is to execute INSTEAD OF performing DML on the view. There is no way to go back to the "normal DML" when the INSTEAD OF trigger exists.
    You can put all of the logic you will need in the INSTEAD OF trigger and use IF conditions. Use IF logic to code both your special and "normal" processing.
    3. I want to avoid writing as much manual DML code as possible for long-term maintainability.You will have to code the operative lines somewhere. Reusable functions and/or procedures in a package?Yep using an "IF" I knew about...no problem there.
    But was just looking for a cheap and easy way to say (for the "else" condition) to revert to normal DML processing. Sounds like in a DB trigger there is no such syntax I guess.
    This is an example from Oracle Forms, I was looking for a database equivalent of this(see http://sqltech.cl/doc/dev2000/help/fbhelp18.htm):
    Built-in Subprograms for On-Event Triggers For most of the transactional On-event triggers, there is a corresponding built-in subprogram.
    On-Event Trigger
    Corresponding Built-in
    On-Delete
    DELETE_RECORD
    On-Insert
    INSERT_RECORD
    On-Update
    UPDATE_RECORD
    When you call one of these built-in subprograms from its corresponding transactional trigger, Form Builder performs the default processing that it would have done normally at that point in the transaction.
    For example, if you call the INSERT_RECORD procedure from an On-Insert trigger, Form Builder performs the default processing for inserting a record in the database during a commit operation.
    When these built-ins are issued from within their corresponding transactional triggers, they are known as do-the-right-thing built-ins. That is, they do what Form Builder would normally have done at that point if no trigger had been present. Thus, an On-Insert trigger that calls the INSERT_RECORD procedure is functionally equivalent to not having an On-Insert trigger at all. Such a trigger is explicitly telling Form Builder to do what it would have done by default anyway.Note that the author calls them the "do-the-right-thing" built-ins. That's what I was looking for but on the DB side. Sounds like Oracle didn't come up with that (yet)?

  • Problem with forms6i using Pre-Insert Trigger

    I created a block level pre-insert trigger to do some validations and when I save the first time with wrong data it is working fine and popping up alerts that I defined but if I press save the second time it is saving even though the data is wrong.
    This is in Applications 11.5.10 using all the property classes and running on the server.
    I created exact replica of the form(no applications, property classes
    just basic form but with same functionality) and ran it on my local machine it is working fine. It is giving error till the data is fixed.
    Anybody know why?
    Thanks in advance

    It did not work. It is still doing the samething. Actually it is popping up my alerts but saving the record first time itself. Is there any way I can tell it not to save if the data is wrong. My code is below it basically pops up the alerts but doesn't tell anywhere not to save it.
    Thanks
    VJ
    declare
         v_amount number;
         alert_id      ALERT := Find_Alert('amount_from');
         alert_id1 ALERT := Find_Alert('amount_to');
         dummy_var NUMBER;
    begin
         select max(ssibe_amount_to) into v_amount from ssibe_orderappr_tab where
              ssibe_account_number = :ssibe_orderappr.ssibe_account_number;
              if :ssibe_orderappr.ssibe_amount_from <= v_amount
              then
                   Set_Alert_Property(alert_id, ALERT_MESSAGE_TEXT, 'Amount_From should be greater than '|| v_amount);
                   dummy_var := Show_Alert(alert_id);
              else
                   IF (:SSIBE_ORDERAPPR.SSIBE_AMOUNT_TO <= :SSIBE_ORDERAPPR.SSIBE_AMOUNT_FROM)
                   THEN
                   dummy_var := Show_Alert(alert_id1);
                   end if;
              end if;
    end;

  • 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

  • Mutating table exception on trigger with After Insert but not with before

    Hi
    I need to maintain some constraint on the table to have only one row for values of the columns but not by primary key constraint.
    Because in case of primary key the insert would fail and the rest of the operation would be discontinued, I cannot change in the somponent that inserts the row so I have to prevent that on the table I have.
    I created a before insert trigger on the table which checks if any row exists in the table with same column values as the one being inserted. if found I delete the rows and let the insert happen (w/o raising any error). if the rows do not exist then the insert shall be continued.
    I read at place that modifying the dame table in the trigger body shall raise a mutating table exception, but I donot get the exception when the trigger is fired.
    Just when I change the trigger to after insert trigger then the nutating table exception is thrown.
    Is it the right behavior i.e. the Before insert trigger does not raise the exception and only after insert does that, since I could not find the example for before insert triggers throwing such exception so I think it is better to confirm it before finalizing the implementation.
    Thanks
    Sapan

    sapan wrote:
    Hi Tubby
    I cannot user unique constraint because that would raise an exception upon violation and the third party component that is inserting in the table would fail.
    That component does some other tasks as well after this insert and if an exception is raised then those tasks would not be performed.
    Also I cannot change the component to ignore this exception.Well then, you're in a bit of a pickle.
    I'm guessing the trigger you have been working on isn't "safe". By that i mean that it doesn't account for multi-user scenarios. You'll need to serialize access to the data elements in question and implement some sort of locking mechanism to ensure that only 1 session can work with those values.
    After you work out how to do that it sounds as though you would be better served using an INSTEAD OF trigger (you'd need to implement this on a view which is made off of your base table).
    Here's one way you can work on serializing access to your table on a relatively fine grained level (as opposed to locking the entire table).
    Re: possible to lock stored procedure so only one session may run it at a time?
    Cheers,

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

  • Action with a condition that checks for a survey filled in a transaction

    Hi!
    I need to create an action with a condition that checks if there is a survey filled in the complaint document.
    Is there any way to do it?
    Thanks a lot!
    Susana Messias

    Hi Siva,
    Thanks for the document.
    My scenario its the following:
    I have a complaint with a survey assigned to it. I need to create an action that creates a follow-up task to the person responsible when the status is equal to Completed and the survey it's not filled.
    I customized the action profile as you said, but the problem is to create a condition with the information about the survey. The field status it's ok to insert in a condition, but how about the survey?
    Any ideas?!
    Susana Messias

  • 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

Maybe you are looking for