1

I want to execute a trigger and that should be applied to all users except one user.

How do I write this?

Please provide a simple code example?

Ollie
  • 17,058
  • 7
  • 48
  • 59

2 Answers2

5
if user != 'BADGUY' then
--  run this code
end if;
Randy
  • 16,480
  • 1
  • 37
  • 55
  • 1
    You may want to add `and sys_context('userenv', 'current_user') != 'BADGUY'` if you also want to prevent their definer's rights objects from calling the trigger. See http://stackoverflow.com/a/11005177/409172 – Jon Heller Jul 09 '12 at 18:14
2
 CREATE OR REPLACE TRIGGER <trigger_name>
 :
 DECLARE


 BEGIN

   --replace scott with the user you want to restrict 
   IF sys_context( 'userenv', 'current_user' ) <> 'SCOTT' THEN  
     --do what you want to do 

   END IF;

 END <trigger_name>;
Gaurav Soni
  • 6,278
  • 9
  • 52
  • 72