我在努力为学生人数获得正确价值时遇到问题。我需要使用游标,我的程序的输出应该是这样的......我正在寻找从这里开始的正确方向,因为我有点困惑。谢谢!
Class Name Number of Students
=================================
Biology 6
Calc 3
German 5
这是我当前的代码:
DECLARE
CURSOR c_1 IS
SELECT c.class_name, AVG(s.grade)
FROM class c, student s
WHERE c.class_id = s.class_id
GROUP BY class_name
ORDER BY class_name;
grade_rec c_1%ROWTYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE(('Class Name') || ' ' || ('NUMBER OF Students'));
DBMS_OUTPUT.PUT_LINE('--------------------------------------');
FOR grade_rec IN c_1 LOOP
DBMS_OUTPUT.PUT_LINE(rpad(grade_rec.class_name, 15) ||
' ' || lpad(grade_rec.avg_grade, 10));
END LOOP;
END;