PL/SQL Cursor Exercises: FETCH more than one record and single column from a table
PL/SQL Cursor: Exercise-16 with Solution
Write a program in PL/SQL to FETCH more than one record and single column from a table.
Sample Solution:
PL/SQL Code:
DECLARE
v_emp_name VARCHAR2(20);
CURSOR cur_emp_name IS
SELECT first_name
FROM employees;
BEGIN
OPEN cur_emp_name;
LOOP
FETCH cur_emp_name
INTO v_emp_name;
EXIT
WHEN cur_emp_name%NOTFOUND;
dbms_output.put_line('Name of employee: ’
|| v_emp_name);
END LOOP;
CLOSE cur_emp_name;
END;
/
Sample Output:
SQL> / Name of employee: Ellen Name of employee: Sundar Name of employee: Mozhe Name of employee: David Name of employee: Hermann Name of employee: Shelli Name of employee: Amit Name of employee: Elizabeth
Flowchart:
Improve this sample solution and post your code through Disqus
Previous: Write a program in PL/SQL to FETCH single record and single column from a table.
Next: Write a program in PL/SQL to FETCH multiple records and more than one columns from the same table.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework