Advertisement
havk144

Untitled

Nov 24th, 2022 (edited)
1,582
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 0.65 KB | None | 1 0
  1. DECLARE
  2.     points NUMBER;
  3.  
  4.     CURSOR all_student_ids IS SELECT s.ID_STUDENT FROM STUDENCI s;
  5.  
  6.     FUNCTION get_student_score (p_id_student NUMBER) RETURN NUMBER IS
  7.         score NUMBER;
  8.         BEGIN
  9.             SELECT NVL(SUM(punkty), 0) INTO score FROM egzaminy WHERE ID_STUDENT = p_id_student;
  10.             RETURN score;
  11.         END get_student_score;
  12.  
  13. BEGIN
  14.     FOR student IN all_student_ids LOOP
  15.         points := get_student_score(student.id_student);
  16.         IF points != 0 THEN
  17.             DBMS_OUTPUT.put_line('Suma punktów studenta o ID ' || student.id_student || ': ' || points);
  18.         ELSE
  19.             DBMS_OUTPUT.put_line('Student o ID ' || student.id_student || ' nie zdawał egzaminu');
  20.         END IF;
  21.     END LOOP;
  22. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement