Chapter 9 Introduction to Cursors

1)Write a nested cursor where the parent cursor calls information about each section of a course. The child cursor counts the enrollment. The only output is one line for each course with the Course Name and Section Number and the total enrollment.
A1: Answer: Your answer should look similar to the following:
 SET SERVEROUTPUT ON DECLARE CURSOR c_course IS SELECT course_no, description FROM course WHERE course_no < 120; CURSOR c_enrollment(p_course_no IN course.course_no%TYPE) IS SELECT s.section_no section_no, count(*) count FROM section s, enrollment e WHERE s.course_no = p_course_no AND s.section_id = e.section_id GROUP BY s.section_no; BEGIN FOR r_course IN c_course LOOP DBMS_OUTPUT.PUT_LINE (r_course.course_no||' ...

Get Oracle® PL/SQL® Interactive Workbook, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.