Cursor to Display Total Amount of EVS Book in Books Table

Cursor to Display Total Amount of EVS Book in Books Table


 DECLARE

   CURSOR Totalamount_cursor(book_name VARCHAR2) IS

      SELECT total_amount

      FROM books

      WHERE name = book_name;


   total_amount NUMBER := 0;

   fetched_amount NUMBER;


BEGIN

   OPEN Totalamount_cursor('EVS');


   LOOP

      FETCH Totalamount_cursor INTO fetched_amount;


      DBMS_OUTPUT.PUT_LINE('Book Price: ' || fetched_amount); -- Debug statement


      EXIT WHEN Totalamount_cursor%NOTFOUND;


      total_amount := total_amount + fetched_amount;


      DBMS_OUTPUT.PUT_LINE('Book total amount: ' || total_amount); -- Debug statement

   END LOOP;


   CLOSE Totalamount_cursor;


END;

/


Output:

SQL> @C:\Users\Admin\Desktop\Oracle\cursor2.sql

Book Price: 5000

Book total amount: 5000

Book Price: 5000

Book total amount: 10000

Book Price: 5000

Book total amount: 15000

Book Price: 5000

Book total amount: 20000

Book Price: 5000

Book total amount: 25000

Book Price: 5000

Book total amount: 30000

Book Price: 5000

Book total amount: 35000

Book Price: 5000

Book total amount: 40000

Book Price: 5000

Book total amount: 45000

Book Price: 5000

Book total amount: 50000

Book Price: 5000

Book total amount: 55000

Book Price: 5000

Book total amount: 60000

Book Price: 5000

Book total amount: 65000

Book Price: 5000

Book total amount: 70000

Book Price:

Book total amount:

Book Price:


PL/SQL procedure successfully completed.


टिप्पणी पोस्ट करा

0 टिप्पण्या