1
votes

I'm Learning Oracle and wanted to try creating a trigger. I tried this example form a book in sqlplus.

SQL> CREATE OR REPLACE TRIGGER policy_bull BEFORE insert or update
  2  ON emp
  3  FOR EACH ROW
  4  BEGIN
  5    :new.salary := 200;
  6  END
  7  /

ERROR at line 1: ORA-04089: cannot create triggers on objects owned by SYS

even though I logged in as SYS using

sqlplus "sys/oracle as sysdba"

4
can you try it without semicolons? - jle
Did the book tell you to log in as sys? sys is similar to the "root" user in unix - only used for administering the system. Typically the first thing you'd do with a new Oracle instance is create a user who will own the objects for an application. For experiments you may find the user "scott", password "tiger" has already been created for this purpose (however, on a new instance, you may have to unlock the account first). - Jeffrey Kemp

4 Answers

7
votes

You need to type / on a blank line to tell SQLPLUS to run the statement.

6
votes

Oracle forbids creating triggers on objects owned by SYS.

Did you create the table emp as SYS? You probably want to be a regular user to do that. emp doesn't sound like a system table.

0
votes

I think a semi-colon is missing after END. Also mention SYS.emp

0
votes

SQL> CREATE OR REPLACE TRIGGER policy_bull BEFORE insert or update 2 of SALARY on EMP 3 FOR EACH ROW 4 BEGIN 5 :new.salary := 200; 6 END 7 /

you have to type the column where the "NEW SALARY" is ppl its SALARY so ...or update of SALARY on EMP...