FUNCTION calc_term_gpa (curr_s_id NUMBER, curr_term_id NUMBER) RETURN NUMBER IS CURSOR credits_cursor IS SELECT s_id, credits, grade FROM enrollment, course_section, course WHERE enrollment.c_sec_id = course_section.c_sec_id AND course_section.course_id = course.course_id AND s_id = curr_s_id AND term_id = curr_term_id AND grade IS NOT NULL; credits_row credits_cursor%ROWTYPE; total_credits NUMBER(3); grade_points NUMBER(1); grade_credit_points NUMBER(3); total_credit_points NUMBER(3); student_gpa NUMBER := 0; BEGIN total_credit_points := 0; total_credits := 0; FOR credits_row IN credits_cursor LOOP IF credits_row.grade = 'A' THEN grade_points := 4; ELSIF credits_row.grade = 'B' THEN grade_points := 3; ELSIF credits_row.grade = 'C' THEN grade_points := 2; ELSIF credits_row.grade = 'D' THEN grade_points := 1; ELSE grade_points := 0; END IF; grade_credit_points := grade_points * credits_row.credits; total_credit_points := total_credit_points + grade_credit_points; total_credits := total_credits + credits_row.credits; END LOOP; student_gpa := total_credit_points/total_credits; RETURN student_gpa; EXCEPTION WHEN zero_divide THEN student_gpa := 0; RETURN student_gpa; END;