You are on page 1of 2

Q6.

Write a PL/SQL code to display the employee whose data is stored in emp1 table having attribute empno, empname, empjob, hiredate. The employee who has given service to the organization more than 15 years, If such employees are present then show the empno, empname along with the message Service given for 15 years or No such employee.

1 declare 2 v_hiredate emp1.hiredate%type; 3 v_date date; 4 v_empid emp1.empid%type:=&v_empid; 5 v_months number(10); 6 begin 7 select hiredate into v_hiredate from emp1 where 8 v_empid=empid; 9 v_months:=Floor(months_between(sysdate,v_hiredate)/12); 10 if v_months>=15 then 11 dbms_output.put_line('Service given for 15 years!'); 12 else 13 dbms_output.put_line('Service given for'||v_months||'years!'); 14 end if; 15* end; SQL> / Enter value for v_empid: 1 old 4: v_empid emp1.empid%type:=&v_empid;

new 4: v_empid emp1.empid%type:=1; Service given for 15 years!

PL/SQL procedure successfully completed.

You might also like