DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: triggers

  1. #1
    Join Date
    Feb 2001
    Posts
    103
    Hi guys,

    I am writing a trigger. The code is as under :-

    table :- Emp_test

    empno Number
    ename Varchar2(25)
    Crt_by Varchar2(25)
    Cdate date

    I am written a trigger on the above table

    Create or replace trigger emp_trig before insert on emp_test for each row
    declare
    a varchar2(25);
    b date;
    begin
    select user into a from dual;
    select sysdate into b from dual;
    if inserting then
    update emp_test set crt_by=a and cdate=b where rowid=:new.rowid;
    ( i can also write rowid in (select max(rowid) from emp_test)
    end if;
    end;

    When i am trying to insert multiple records into the table its giving me mutating table error.. I tried creating it a statement level trigger but in that case it updates only the last row of the table with user and sysdate while i want all the rows to get updated which have been inserted..
    I have also tried doing it through view but it does not works..

    Thanks in advance
    When the going gets tough, the tough gets going

  2. #2
    Join Date
    Feb 2001
    Location
    Paris, France
    Posts
    809
    why do you update ??? you can just change the values of crt_by and cdate you're going to insert ...
    moreover if I was updating, I wouldn't use the rowid since I'm not sure it is already affected BEFORE insert ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width