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:

Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 20 years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.