Tuesday , April 30 2024

Oracle PL/SQL Cursor

This article contains information about Oracle PL/SQL Cursor and example about PL/SQL Cursor.

What is Oracle PL/SQL Cursor?

When the data in a table is listed, we can read the data row by row using the cursor and we can operate on these rows.

By using various values ​​in the cursor, it receives information about whether it is at the end of the record list and whether there is data.

Oracle Cursor Types

There are two types of Cursors;

  • Implicit
  • Explicit

Implicit Cursor in PL/SQL

When the database queries run, the cursor created and managed by oracle is called Implicit Cursor.

We can not control this cursor type.

Explicit Cursor in PL/SQL

This is the cursor most of us knows. We can control this cursor type.

If we need the perform something(query execution, calculation) for all the rows of a query result set we can use cursor.

We can define cursor as follows;

Sample Cursor Definition;

Once the cursor is defined, we open the Cursor with the OPEN keyword.

After opening the cursor , the values ​​are fetched with FETCH keyword.

After the process is completed, we close the Cursor with the CLOSE keyword.

Sample Cursor Usage is as follows;

We created the variables to be used in the DECLARE according to the table data type and a cursor and query with CURSOR.

Then we opened a cursor in BEGIN, we ran the query step by step with LOOP and FETCH.

Using IF in the FETCH block, we compared the value received with the cursor.

At the end of the BEGIN , we returned the memory by closing the cursor.

Thanks to the cursor, we had the opportunity to run PL / SQL commands on the data step by step.

You can find more detailed information about below topics in the below link.

PL/SQL Tutorial

You will find below topics in this article.

  1. What is PL/SQL
  2. Oracle PL/SQL Data Types and Variables and Literals
  3. Oracle PL/SQL Operators
  4. Oracle PL/SQL Conditional Statements
  5. Oracle PL/SQL Loops
  6. Oracle PL/SQL Procedures and Procedure Parameters
  7. Oracle PL/SQL Functions
  8. Oracle PL/SQL Cursor
  9. Oracle PL/SQL Records
  10. Oracle PL/SQL Exception
  11. Oracle PL/SQL Trigger
  12. Oracle PL/SQL Packages
  13. Oracle PL/SQL Collections

You can find more information about cursor at docs.oracle.com

Loading

About Yusuf SEZER

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories