Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

PL/SQL Cursor Exercises: FETCH single record and single column from a table

PL/SQL Cursor: Exercise-15 with Solution

Write a program in PL/SQL to FETCH single record and single column from a table.

Sample Solution:

PL/SQL Code:

DECLARE
  v_emp_name VARCHAR2(50);
  CURSOR emp_cur_name IS
    SELECT first_name
    FROM   employees
    WHERE  employee_id = 105;

BEGIN
  OPEN emp_cur_name;
  FETCH emp_cur_name
  INTO  v_emp_name;
  
  dbms_output.put_line('The name of the employee is:’
  || v_emp_name);
  CLOSE emp_cur_name;
END;
/

Sample Output:

SQL> /
The name of the employee is:David

PL/SQL procedure successfully completed.

Flowchart:

Flowchart: PL/SQL Cursor Exercises - FETCH single record and single column from a table

Improve this sample solution and post your code through Disqus

Previous: Create a PL/SQL block to increase salary of employees in the department 50 using WHERE CURRENT OF clause.
Next: Write a program in PL/SQL to FETCH more than one record and single column from a table.

What is the difficulty level of this exercise?