Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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.
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
Step: 1
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 ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started