CREATE SEQUENCE Emp_seq
START WITH 8000
INCREMENT BY 3;

CREATE OR REPLACE TRIGGER Sekwencja
BEFORE INSERT
ON emp
FOR EACH ROW
BEGIN
  IF :NEW.empno IS NULL THEN
    SELECT Emp_seq.NextVal INTO :NEW.empno FROM dual;
  END IF;
END;
/

INSERT INTO emp(ename, job, sal, comm, deptno) VALUES('LEON', 'CLEANER', '5000', '5000', 40);
INSERT INTO emp(ename, job, sal, deptno) VALUES('MR BEAN', 'ACTOR', '2000', 40);
SELECT empno, ename FROM emp WHERE deptno = 40;
ROLLBACK;

DROP TRIGGER Sekwencja;
DROP SEQUENCE Emp_seq;
