Summary: in this tutorial, we will introduce you to PL/SQL cursor.
You will learn step by step how to use a cursor to loop through a set of rows and process each row individually.
When you OPEN the cursor, PL/SQL executes the SQL SELECT statement and identifies the active result set.
Notice that the Once the cursor is open, you can fetch data from the cursor into a record that has the same structure as the cursor.
As the result, Oracle created PL/SQL cursor to provide these extensions.
A PL/SQL cursor is a pointer that points to the result set of an SQL query against database tables.
statements might credit one bank account and debit another.
It is important not to allow one operation to succeed while the other fails.
We can also create a record with a cursor by replacing the table name with the cursor name.
Here ‘emp_tbl’ in the table which contains records of all the employees. On every fetch statement, the pointer moves to the next row.
2) Accessing the records in the cursor: Once the cursor is created in the declaration section we can access the cursor in the execution section of the PL/SQL program. If you want to fetch after the last row, the program will throw an error.
PL/SQL also conforms to the current ANSI/ISO SQL standard.
In addition to static SQL discussed in this chapter, PL/SQL also supports dynamic SQL, which enables you to execute SQL data definition, data control, and session control statements dynamically.