CREATE TABLE emp ( enpno varchar(4), empname varchar(30), designation varchar2(10), category char(1), basicsalary number(4), joined date )
DECLARE exp_check exception;
CURSOR c1 IS
SELECT empname,
joined
FROM emp;
BEGIN
FOR i IN c1 LOOP if(trunc(months_between(sysdate,i.joined)/12)<2) THEN RAISE exp_check;
ELSE
INSERT INTO tempp2
VALUES(i.empname,
trunc(months_between(sysdate,i.joined)/12));
END IF;
END LOOP;
exception WHEN exp_check THEN dbms_output.put_line('experiance is less then 2 years not allowed');
WHEN others THEN dbms_output.put_line('un identified error occured');
END;
/