0

I have a table practise_one with two columns ID and NAME and data as following,

ID name : 1 sammy, 2 vam, 3 mam, 4 pam, 5 jam,

I have defined an autonomous trigger after insert or update or delete on the table for each row.

I want all the id that are greater than 8 and are inserted into the table practise_one to be filtered out (to not be inserted into the table) only id's less than 8 can be inserted into the table. All the id's greater than 8 should be inserted into a different table practise_one_log.

My Approach of trigger:

create or replace trigger tr_practise_one 
after insert or update or delete on practise_one
for each row
Declare
  pragma autonomous_transaction;
  id_greater exception;
  id_one number(10);
begin
  if (:new.id>8) then
   rollback;
   raise id_greater;
  end if;
exception 
  when id_greater then
  insert into practise_one_log values('The Id is greater '||:new.id);
  commit;
end tr_practise_one;

When I do :

insert into practise_one values (9,'oam');

I am able to get the respective row into the table 'practise_one_log' but still I am unable to stop the row from getting into the table practise_one.

Resultant Output:

  ID    name :
  1 sammy,
  2 vam,
  3 mam,
  4 pam,
  5 jam,
  9     oam

Expected Output

  ID    name :
  1 sammy,
  2 vam,
  3 mam,
  4 pam,
  5 jam
4

1 回答 1

0

You can use BEFORE trigger or INSTEAD OF. http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_7004.htm

于 2013-10-29T07:35:54.483 回答