DECLARE
emp_first_name VARCHAR2(35);
emp_last_name VARCHAR2(35);
zemp_id NUMBER:=&employee_id;
BEGIN
SELECT first_name,
last_name
INTO emp_first_name, emp_last_name
FROM employees
WHERE employee_id = zemp_id;
dbms_output.Put_line ('Employee name: '
|| emp_first_name
||' '
||emp_last_name);
EXCEPTION
WHEN no_data_found THEN
dbms_output.Put_line ('There is no employee with the ID '||to_char(zemp_id));
END;
/
Sample Output:
SQL> /
Enter value for employee_id: 485
old 4: zemp_id NUMBER:=&employee_id;
new 4: zemp_id NUMBER:=485;
There is no employee with the ID 485
PL/SQL procedure successfully completed.
SQL> /
Enter value for employee_id: 147
old 4: zemp_id NUMBER:=&employee_id;
new 4: zemp_id NUMBER:=147;
Employee name: Alberto Errazuriz
PL/SQL procedure successfully completed.
PL/SQL opens an implicit cursor with the SELECT INTO statement and after the SELECT INTO
statement completes, closes the implicit cursor.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer