Cursor Program to Retrieve Data from Books Table and Display the Result

Cursor Program to Retrieve Data from Books Table and Display the Result


 DECLARE

   CURSOR book_cursor IS

    SELECT book_id,name, price

    from books;

    book_id books.book_id%type;

    name books.name%type;

   price books.price%type;

   Begin

   open book_cursor;

   Loop

  fetch book_cursor into book_id,name, price;

   exit when book_cursor%Notfound;

   DBMS_OUTPUT.PUT_Line('Book ID: ' || book_id || ' ' ||'Book Name: ' || Name  ||' ' || 'Book Price : ' || price);

   End Loop;

   close book_cursor;

   End;

   /


Result:

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

Book ID: 101 Book Name: EVS Book Price : 200

Book ID: 102 Book Name: EVS Book Price : 200

Book ID: 103 Book Name: EVS Book Price : 200

Book ID: 104 Book Name: EVS Book Price : 200

Book ID: 105 Book Name: EVS Book Price : 200

Book ID: 106 Book Name: EVS Book Price : 200

Book ID: 107 Book Name: EVS Book Price : 200

Book ID: 108 Book Name: EVS Book Price : 200

Book ID: 109 Book Name: EVS Book Price : 200

Book ID: 110 Book Name: EVS Book Price : 200

Book ID: 112 Book Name: EVS Book Price : 200

Book ID: 113 Book Name: EVS Book Price : 200

Book ID: 114 Book Name: EVS Book Price : 200

Book ID: 115 Book Name: EVS Book Price : 200

Book ID: 116 Book Name: EVS Book Price : 200


PL/SQL procedure successfully completed.


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

0 टिप्पण्या