CREATE OR REPLACE TRIGGER Sprawdzanie_zarobkow
BEFORE UPDATE OF sal
ON emp
FOR EACH ROW
DECLARE
  minimum NUMBER;
  maksimum NUMBER;
  skala NUMBER;
BEGIN
  SELECT losal, hisal, grade
  INTO minimum, maksimum, skala
  FROM salgrade
  WHERE :OLD.sal BETWEEN losal AND hisal;

  IF NOT (:NEW.sal BETWEEN minimum AND maksimum) THEN
    Raise_application_error(-20500, 'Zarobki='||:NEW.sal||' spoza zakresu='||skala||'!');
  END IF;
END;
/

UPDATE emp SET sal = 2*sal WHERE ename = 'MILLER';

DROP TRIGGER Sprawdzanie_zarobkow;
