PL/SQL Cursor Exercises: FETCH multiple records and more than one columns from different tables
PL/SQL Cursor: Exercise-18 with Solution
Write a program in PL/SQL to FETCH multiple records and more than one columns from different tables.
Below example we are trying to fetch department names and employee names.
DECLARE CURSOR cur_emp_name IS SELECT first_name, last_name, department_name FROM employees e, departments d WHERE d.department_id = e.department_id; v_emp_rec cur_emp_name%ROWTYPE; BEGIN OPEN cur_emp_name; LOOP FETCH cur_emp_name INTO v_emp_rec; exit WHEN cur_emp_name%NOTFOUND; dbms_output.Put_line('Name: ' || v_emp_rec.first_name || ' ' ||v_emp_rec.last_name || ' :: department: ' || v_emp_rec.department_name); END LOOP; CLOSE cur_emp_name; END; /
SQL> / Name: Jennifer Whalen :: department: Administration Name: Pat Fay :: department: Marketing Name: Michael Hartstein :: department: Marketing Name: Sigal Tobias :: department: Purchasing Name: Karen Colmenares :: department: Purchasing Name: Shelli Baida :: department: Purchasing Name: Den Raphaely :: department: Purchasing Name: Alexander Khoo :: department: Purchasing Name: Guy Himuro :: department: Purchasing Name: Susan Mavris :: department: Human Resources Name: Kevin Feeney :: department: Shipping Name: Jean Fleaur :: department: Shipping Name: Adam Fripp :: department: Shipping ...
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
- New Content published on w3resource :
- 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