PL/SQL Program to Print Employee Details

In this tutorial, you will learn how to print employee details using PL/SQL program.

PL/SQL Program to Print Employee Details

In the following example, it will print the employee details for the employee number 7839, set in the declare section of the PL/SQL program.

SET SERVEROUTPUT ON;
DECLARE
n_empno INTEGER := 7839;
v_ename emp.ename%TYPE;
v_job emp.job%TYPE;
n_mgr emp.mgr%TYPE;
n_sal emp.sal%TYPE;
d_hiredate emp.hiredate%TYPE;
n_deptno emp.deptno%TYPE;
BEGIN
SELECT ename,
job,
mgr,
hiredate,
sal,
deptno
INTO v_ename,
v_job,
n_mgr,
d_hiredate,
n_sal,
n_deptno
FROM emp
WHERE empno = n_empno;

DBMS_OUTPUT.put_line ('Employee Name: ' || v_ename);
DBMS_OUTPUT.put_line ('Job: ' || v_job);
DBMS_OUTPUT.put_line ('Manager: ' || n_mgr);
DBMS_OUTPUT.put_line ('Hiredate: ' || d_hiredate);
DBMS_OUTPUT.put_line ('Salary: ' || n_sal);
DBMS_OUTPUT.put_line ('Department: ' || n_deptno);
Exception
 When others then
DBMS_OUTPUT.put_line ('Error: ' || sqlerrm);   
END;
/

Output:

Employee Name: KING
Job: PRESIDENT
Manager: 
Hiredate: 17-NOV-81
Salary: 5000
Department: 10
PL/SQL procedure successfully completed.

See also:

Get more Vinish.dev tutorials on Google

See my articles more often when you search Google.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted