Skip to main content

Oracle Trigger (10g)

Comments

1 comment

  • David Paras

    A trigger running fine on Oracle SQL editor does not work on Adeptia “SQL Trigger” text area present at “Database Trigger Activity” creation GUI of Adeptia Suite.

    This is found to be Oracle version specific issue and happens in case of Oracle 10g and works fine on Oracle 11g. On further investigation, we now conclude that Oracle 10g fails to execute Trigger Query string that contains carriage return (\r) along with newline character (\n) which makes this trigger invalid.

    Oracle 11g works fine with Trigger Query strings containing carriage return (\r) along with newline character (\n).

    If you are using Oracle 10g or a lower version, avoid this issue by  removing the carriage return (\r) from the query string before providing it to Adeptia “SQL Trigger” text area present at “Database Trigger Activity” creation GUI of Adeptia Suite. You can do this by following below steps:-

    1. Copy and paste your trigger on a text editor that supports searching of new line characters.
    2. Search for '\n' and replace them with blank string.
    3. Copy this trigger query string from textpad editor and paste it at “SQL Trigger” text area of “Database Trigger Activity”. This will result the creation of a valid trigger in case of Oracle 10g.

    Here is the example trigger that we tested on Adeptia and can be used as reference:-

    create or replace trigger TestTrigger
    AFTER insert or update of id
    on test
    for each row
    declare
    cursor cursor_project is
    select project_num from project where client_num = 'abc';
    temp_project varchar2(30);
    begin
    open cursor_project;
    loop
    fetch cursor_project into temp_project;
    exit when cursor_project%NOTFOUND;
    if :new.id = temp_project then
    INSERT INTO dbeventtriggertable VALUES ('Query = where id='||:new.id);
    end if;
    end loop;
    END;

    For executing this trigger on Oracle 10g through Adeptia Database Trigger Activity we replaced the \n&\r charecters using a textpad editor as below:-

     

    create or replace trigger TestTrigger AFTER insert or update of id on test for each row declare cursor cursor_project is select project_num from project where client_num = 'abc'; temp_project varchar2(30); begin open cursor_project;loop fetch cursor_project into temp_project;exit when cursor_project%NOTFOUND;if :new.id = temp_project then INSERT INTO dbeventtriggertable VALUES ( '010000002015133890788500200007','Query = where id='||:new.id, sysdate );end if; end loop; END;
    0

Please sign in to leave a comment.