SlideShare a Scribd company logo
CURSORS in ORACLE
Definition A cursor is a SELECT statement that is defined within the declaration section of your PL/SQL code. Oracle will allocate an area of memory known as the context area.  The context area contains information necessary to complete the processing, including the number of rows processed by a statement, and in the case of a query, the active set, which is the set of rows returned by a query. A cursor is a handle or a pointer to the context area.
Steps in Processing a Cursor Declaring a Cursor – Declaration of the variables and Cursor. OPEN  Statement – Opens the Cursor for a query. FETCH Statement – Fetches the cursor values i.e., the results into PL/SQL variables. CLOSE Statement – Closes the Cursor. Cursor Attributes (%FOUND, %NOTFOUND, %ISOPEN, %ROWCOUNT)
Types of Cursors The cursors are classified as  Explicit Cursors Implicit Cursors Implicit cursors are opened for every DML statement. Oracle handles it  automatically ,so we don’t have to write code to handle it. Explicit Cursor has to be defined. Cursor is called explicit,  when user  names the cursor and associates it with query. This is the very first step  when dealing with explicit cursors. It is known as defining or  declaring a cursor.  Next three phases are Opening a cursor (This will initialize the cursor and identifies the result set.) Fetching data from a cursor (This will retrieve the result  set for the executed query) Closing a cursor (Once execution is done, disable the cursor)
Cursor Attributes % FOUND  – Returns true if the record or data is found, else returns false. % NOTFOUND  - Returns true if the record or data is not found, else returns false. % ISOPEN  -   Always returns False in case of implicit cursors as cursor is closed internally immediately after execution. % ROWCOUNT  -  number of records effected by DML or SELECT statement.
Example DECLARE V_studentID  students.id % TYPE; V_FirstName  students.first_name % TYPE; V_LastName  students.last_name % TYPE; V_Major  students.major % TYPE:=‘computer Science’; CURSOR  C_students  IS SELECT id, first_name,last_name  FROM students WHERE  major=V_Major; BEGIN OPEN C_students; LOOP FETCH C_students INTO V_studentID,V_FirstName,V_LastName; EXIT WHEN C_students % NOTFOUND; ENDLOOP; CLOSE C_students; END;

More Related Content

What's hot (20)

PPT
Control statments in c
CGC Technical campus,Mohali
 
PPT
The Three Basic Selection Structures in C++ Programming Concepts
Tech
 
PPT
Control statements and functions in c
vampugani
 
PPT
Control Structures
Ghaffar Khan
 
PPTX
Conditional statements
cherrybear2014
 
DOCX
Hd3
Prakash Rao
 
PPTX
Chapter 4.1
sotlsoc
 
PPTX
Control statements in c
Sathish Narayanan
 
PPT
Java adapter
Arati Gadgil
 
PPTX
Control structures in java
VINOTH R
 
PPTX
Control statement-Selective
Nurul Zakiah Zamri Tan
 
PPTX
Control Statements in Java
Niloy Saha
 
PPT
Control structures selection
Online
 
PPT
Control structures ii
Ahmad Idrees
 
PPTX
PL/SQL Introduction
Phanindra Oruganti
 
PPTX
C# conditional branching statement
baabtra.com - No. 1 supplier of quality freshers
 
PPSX
Conditional statement
Maxie Santos
 
PPTX
Selection statements
Harsh Dabas
 
PPTX
Interface java
atiafyrose
 
PPTX
Selection Statements in C Programming
Kamal Acharya
 
Control statments in c
CGC Technical campus,Mohali
 
The Three Basic Selection Structures in C++ Programming Concepts
Tech
 
Control statements and functions in c
vampugani
 
Control Structures
Ghaffar Khan
 
Conditional statements
cherrybear2014
 
Chapter 4.1
sotlsoc
 
Control statements in c
Sathish Narayanan
 
Java adapter
Arati Gadgil
 
Control structures in java
VINOTH R
 
Control statement-Selective
Nurul Zakiah Zamri Tan
 
Control Statements in Java
Niloy Saha
 
Control structures selection
Online
 
Control structures ii
Ahmad Idrees
 
PL/SQL Introduction
Phanindra Oruganti
 
C# conditional branching statement
baabtra.com - No. 1 supplier of quality freshers
 
Conditional statement
Maxie Santos
 
Selection statements
Harsh Dabas
 
Interface java
atiafyrose
 
Selection Statements in C Programming
Kamal Acharya
 

Similar to Cursors in oracle (20)

PDF
PLSQL CURSOR
Arun Sial
 
PPT
4 cursors
Babajan Baig
 
PPTX
plsql tutorialhub....
Abhiram Vijay
 
PPTX
PL/SQL - CURSORS
IshaRana14
 
PDF
Cursors
Isha Aggarwal
 
PDF
Lecture Notes Unit5 chapter19 Cursor in Pl/SQL
Murugan146644
 
PPTX
Cursors
Priyanka Yadav
 
DOC
3963066 pl-sql-notes-only
Ashwin Kumar
 
PPT
Cursors.ppt
Karthick Panneerselvam
 
PPTX
PL_SQL - II.pptx
priyaprakash11
 
PPT
Cursors
Raghav Chhabra
 
PPT
Procedures andcursors
LakshmiSamivel
 
PPT
SQL / PL
srijanani2030
 
PPT
Basic cursors in oracle
Suhel Firdus
 
PPTX
Oracle:Cursors
oracle content
 
PPTX
Oracle: Cursors
DataminingTools Inc
 
PPTX
BBarters_PL_SQL gives cdemo details.pptx
shailesh patil
 
PDF
Pl sql programme
Dhilip Prakash
 
PDF
Pl sql programme
Dhilip Prakash
 
PPT
Plsql
fika sweety
 
PLSQL CURSOR
Arun Sial
 
4 cursors
Babajan Baig
 
plsql tutorialhub....
Abhiram Vijay
 
PL/SQL - CURSORS
IshaRana14
 
Cursors
Isha Aggarwal
 
Lecture Notes Unit5 chapter19 Cursor in Pl/SQL
Murugan146644
 
3963066 pl-sql-notes-only
Ashwin Kumar
 
PL_SQL - II.pptx
priyaprakash11
 
Procedures andcursors
LakshmiSamivel
 
SQL / PL
srijanani2030
 
Basic cursors in oracle
Suhel Firdus
 
Oracle:Cursors
oracle content
 
Oracle: Cursors
DataminingTools Inc
 
BBarters_PL_SQL gives cdemo details.pptx
shailesh patil
 
Pl sql programme
Dhilip Prakash
 
Pl sql programme
Dhilip Prakash
 
Ad

More from Tamizhmuhil (13)

PDF
Ayeesha tamil story by Era.Natarajan
Tamizhmuhil
 
PDF
Ayeesha by Era.Natarajan
Tamizhmuhil
 
PDF
Lecture 343
Tamizhmuhil
 
PDF
Lecture 839
Tamizhmuhil
 
PDF
Tn min-ithazh-pankuni-nanthana
Tamizhmuhil
 
PDF
Kaatruveli
Tamizhmuhil
 
PDF
Algebra formulae
Tamizhmuhil
 
PDF
Tn min-ithazh-thai-nanthana
Tamizhmuhil
 
PDF
இந்த வாரம் கலாரசிகன் Dinamani - tamil daily news
Tamizhmuhil
 
PDF
Kavi visai e-book realesed by tamilaka kavinjar kalai ilakkiya sangam
Tamizhmuhil
 
PDF
Birdhouse gift basket
Tamizhmuhil
 
PPT
Arthropod es tpipeline_poster
Tamizhmuhil
 
PDF
9 sub adenine derivatives-janagi
Tamizhmuhil
 
Ayeesha tamil story by Era.Natarajan
Tamizhmuhil
 
Ayeesha by Era.Natarajan
Tamizhmuhil
 
Lecture 343
Tamizhmuhil
 
Lecture 839
Tamizhmuhil
 
Tn min-ithazh-pankuni-nanthana
Tamizhmuhil
 
Kaatruveli
Tamizhmuhil
 
Algebra formulae
Tamizhmuhil
 
Tn min-ithazh-thai-nanthana
Tamizhmuhil
 
இந்த வாரம் கலாரசிகன் Dinamani - tamil daily news
Tamizhmuhil
 
Kavi visai e-book realesed by tamilaka kavinjar kalai ilakkiya sangam
Tamizhmuhil
 
Birdhouse gift basket
Tamizhmuhil
 
Arthropod es tpipeline_poster
Tamizhmuhil
 
9 sub adenine derivatives-janagi
Tamizhmuhil
 
Ad

Recently uploaded (20)

PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
July Patch Tuesday
Ivanti
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Python basic programing language for automation
DanialHabibi2
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
July Patch Tuesday
Ivanti
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Python basic programing language for automation
DanialHabibi2
 

Cursors in oracle

  • 2. Definition A cursor is a SELECT statement that is defined within the declaration section of your PL/SQL code. Oracle will allocate an area of memory known as the context area. The context area contains information necessary to complete the processing, including the number of rows processed by a statement, and in the case of a query, the active set, which is the set of rows returned by a query. A cursor is a handle or a pointer to the context area.
  • 3. Steps in Processing a Cursor Declaring a Cursor – Declaration of the variables and Cursor. OPEN Statement – Opens the Cursor for a query. FETCH Statement – Fetches the cursor values i.e., the results into PL/SQL variables. CLOSE Statement – Closes the Cursor. Cursor Attributes (%FOUND, %NOTFOUND, %ISOPEN, %ROWCOUNT)
  • 4. Types of Cursors The cursors are classified as Explicit Cursors Implicit Cursors Implicit cursors are opened for every DML statement. Oracle handles it automatically ,so we don’t have to write code to handle it. Explicit Cursor has to be defined. Cursor is called explicit, when user names the cursor and associates it with query. This is the very first step when dealing with explicit cursors. It is known as defining or declaring a cursor. Next three phases are Opening a cursor (This will initialize the cursor and identifies the result set.) Fetching data from a cursor (This will retrieve the result set for the executed query) Closing a cursor (Once execution is done, disable the cursor)
  • 5. Cursor Attributes % FOUND – Returns true if the record or data is found, else returns false. % NOTFOUND - Returns true if the record or data is not found, else returns false. % ISOPEN - Always returns False in case of implicit cursors as cursor is closed internally immediately after execution. % ROWCOUNT - number of records effected by DML or SELECT statement.
  • 6. Example DECLARE V_studentID students.id % TYPE; V_FirstName students.first_name % TYPE; V_LastName students.last_name % TYPE; V_Major students.major % TYPE:=‘computer Science’; CURSOR C_students IS SELECT id, first_name,last_name FROM students WHERE major=V_Major; BEGIN OPEN C_students; LOOP FETCH C_students INTO V_studentID,V_FirstName,V_LastName; EXIT WHEN C_students % NOTFOUND; ENDLOOP; CLOSE C_students; END;