Question: Use the classes table and display the instructor id and class id for each class taught for each instructor. Use a cursor, a basic loop,

Use the classes table and display the instructor id and class id for each class taught for each instructor. Use a cursor, a basic loop, and %ROWTYPE. The results should be arranged in ascending order by instructor and appear as shown below.



Instructor Instructor 3001 teaches 5 class.. 3001 teaches 4 class. 3001 teaches 6 class. Instructor 2) Rewrite the code from  above using a cursor FOR loop.

Instructor Instructor 3001 teaches 5 class.. 3001 teaches 4 class. 3001 teaches 6 class. Instructor Instructor Instructor Instructor = 3003 teaches 3 class. 3003 teaches 2 class.. 3003 teaches 1 class. Statement processed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

sql DECLARE CURSOR instructorclasses IS SELECT instructorid classid FROM classes ORDER BY instructorid classid instructorclassrecord classesROWTYPE BEGIN OPEN instructorclasses LOOP FETCH instructorclasses INTO instructorclassrecord EXIT WHEN instructorclassesNOTFOUND DBMSOUTPUTPUTLINEInstructor instructorclassrecordinstructorid teaches instructorclassrecordclassid class END LOOP CLOSE instructorclasses END This PLSQL block declares a cursor called instructorclasses that selects the instructorid and classid from the classes table and orders the results by instructorid and classid The cursor is opened and a loop is started Inside the loop the FETCH statement retrieves the next row from the instructorclasses cursor into the instructorclassrecord variable The EXIT WHEN statement checks if the cursor has reached the end of the result set If it has the loop is exited If the cursor has not reached the end of the result set the DBMSOUTPUTPUTLINE procedure is used to print the instructor ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!