SET SERVEROUTPUT ON
DECLARE
  v_drive_no      drive.driveno%TYPE;
  v_drive_name    drive.drivename%TYPE;
  v_contamt       donation.contamt%TYPE;
  v_tot_contamt   cont_info.contamt%TYPE;
  hold_driveno    drive.driveno%TYPE;
  CURSOR drive_donation_cursor IS
     SELECT drive.driveno, drivename, contamt  FROM drive, donation
     where donation.driveno = drive.driveno
     ORDER BY drive.driveno;
  BEGIN
     OPEN drive_donation_cursor;
     FETCH drive_donation_cursor INTO v_drive_no, v_drive_name,v_contamt;
     hold_driveno := v_drive_no;
     WHILE drive_donation_cursor%FOUND LOOP
       v_tot_contamt := 0;
       WHILE v_drive_no = hold_driveno and drive_donation_cursor%FOUND LOOP
         v_tot_contamt := v_tot_contamt + v_contamt;
         dbms_output.put_line('The current amount is: '||v_tot_contamt || hold_driveno);
         FETCH drive_donation_cursor INTO v_drive_no, v_drive_name, v_contamt;
       END LOOP;
       INSERT into cont_info
          VALUES(hold_driveno, v_drive_name, v_tot_contamt);
       hold_driveno:= v_drive_no;
     END LOOP;
     CLOSE drive_donation_cursor;
END;
/
SET SERVEROUTPUT OFF
