I have this simple trigger, it work but it gives me a few errors. the syntax seems right.
This is my code:
create or replace
TRIGGER max_raise
BEFORE UPDATE ON empcopy
FOR EACH ROW
DECLARE
v_max NUMBER := 3000;
BEGIN
IF :new.sal > v_max THEN
raise_application_error(-20002, 'Cannot exceed max value of ' || v_max);
END IF;
END;
And this is my errors:
DECLARE
*
ERROR at line 1:
ORA-20002: Cannot exceed max value of 3000
ORA-06512: at "SYSTEM.MAX_RAISE", line 5
ORA-04088: error during execution of trigger 'SYSTEM.MAX_RAISE'
ORA-06512: at line 11
This is this the pl/sql code that i am using in conjunction.
DECLARE
v_raise NUMBER;
CURSOR cur1 IS
SELECT a.deptno, a.sal, a.empno, a.ename
FROM empcopy a;
BEGIN
FOR emp IN cur1 LOOP
v_raise := external_raise(emp.deptno, emp.sal);
DBMS_OUTPUT.PUT_LINE('The Employee: ' || emp.ename || ' new salary: '
|| v_raise || ' the previous one was: ' || emp.sal);
UPDATE empcopy SET sal = v_raise WHERE empno = emp.empno;
END LOOP;
END;
beginexceptionblock if you want to continue on through other records. - Glenn:new.sal - :old.sal) isn't? Also, you really shouldn't be creating your own objects in theSYSTEMschema, you should create a new user and do all of this as that user, if you don't want to pollute the existing (HR?) schema. - Alex Poole