SET SERVEROUTPUT ON
DECLARE
   v_majorcode    majorstudent.majorcode%TYPE;
   v_gradcrs      majorstudent.gradcrs%TYPE;
   v_studentcode  student.studentcode%TYPE;
   v_numcredits   student.numcredits%TYPE;
   v_need         creditsneed.needcr%TYPE;
CURSOR mscursor is
   select majorstudent.majorcode, gradcrs, studentcode, numcredits
       from majorstudent, student
       where majorstudent.majorcode = student.majorcode;
BEGIN
   OPEN mscursor;
   FETCH mscursor into v_majorcode, v_gradcrs, v_studentcode, v_numcredits;
   WHILE mscursor%FOUND loop
        dbms_output.put_line(v_majorcode || ' ' || v_gradcrs || ' ' || v_studentcode || ' ' || v_numcredits);
        v_need := v_gradcrs - v_numcredits;
        dbms_output.put_line(v_need);
        INSERT into creditsneed values(v_studentcode, v_need);
        dbms_output.put_line(v_studentcode || ' ' || v_need);
        FETCH mscursor into v_majorcode, v_gradcrs, v_studentcode, v_numcredits;
   end loop;
   CLOSE mscursor;
END;
/
SET SERVEROUTPUT OFF