Syntax of explicit cursor :
CURSOR cursor_name IS select_statement;
Here we have a table :
SQL> select *from customer; AC_NO B_NO NAME CITY BALANCE COUNT CHK_DATE ---------- ---------- ---------- ---------- ---------- ---------- --------- 111 101 biku surat 7990 1 02-SEP-19 112 103 sunil vapi 11000 1 02-SEP-19 113 102 balram valsad 19000 3 01-JAN-19 114 104 jenna surat 18000 2 01-JAN-19 115 105 sagar mumbai 9000 1 01-JAN-19 116 101 chirag surat 800 3 01-JAN-19 117 102 aditya vapi 500 5 01-JAN-19 118 103 rahul valsad 14000 2 01-JAN-19 119 103 bhavesh mumbai 5000 1 01-JAN-19 120 104 jay surat 400 4 01-JAN-19 121 105 bhola vapi 11000 4 01-JAN-19 AC_NO B_NO NAME CITY BALANCE COUNT CHK_DATE ---------- ---------- ---------- ---------- ---------- ---------- --------- 122 101 sima valsad 8000 2 01-JAN-19 123 102 montu surat 9000 2 01-JAN-19 13 rows selected.
program of explicit cursor :
Result:declare cursor select_customer is select name from customer; m_name varchar2(20); begin open select_customer; -- Open the cursor loop fetch select_customer into m_name; -- fetch the data exit when select_customer%notfound; -- when data is not found dbms_output.put_line(m_name); -- Display the data end loop; close select_customer; -- Close the cursor end; /
SQL> @C:\Users\Vibhuti\cursor.sql biku sunil balram jenna sagar chirag aditya rahul bhavesh jay bhola sima montu PL/SQL procedure successfully completed.
If you like code with vibhu and would like to contribute, you can also write an article using This link :
https://docs.google.com/forms/d/e/1FAIpQLScAmvlPvNUz35R-G0nc_zpRVP3o8xlhtFgC3aKPyLetX_RyXg/viewform?pli=1
OR mail your article to codewithvibhu@gmail.com. See your article appearing on the code with vibhu main page and help other students.
0 Comments