Explain the two type of Cursors ?

Answer Posted / sachin fulari

Brief about Cursors
-------------------
Every SQL statement executed by Oracle has a Private SQL
area that contains info about SQL statement and the set of
data returned.
In PL/SQL, a cursor is a name assigned to a specific
private SQL area of a specific SQL Statement.
There can be either, Static Cursor whose SQL statements is
determined at compile time, or Dynamic Cursor, whose SQL
statement is determined at runtime.

Note: Dynamic Cursors are implemented using Oracle built in
package DBMS_SQL.

Implicit Cursors:
----------------
Any SQL statement that is executed directly or in an PL/SQL
block i.e. execution section or in exception section,
during which it is associated with a work area in memory of
oracle (SGA). This is done using implicit cursor by Oracle.
We do not need to declare implicit cursor hence not be
opened, fetched and closed.

Explicit Cursors:
-----------------

They are the SELECT statement that is declared explicitly
in the declaration section of current block or in a package
specification.
Further we can use open, fetch and close in execution
section or exception section of the block or program to
utilize declared cursor.

To use an explicit cursor we need to declare it in
declaration section of block or package specification.

There are three sub types of explicit cursors:

* Simple Cursor (without parameter)

CURSOR emp_cur IS
SELECT emp_id
FROM emp;

* Parameterized Cursor - That accepts arguments

CURSOR emp_cur (dept_in [IN] NUMBER) IS
SELECT emp_id
FROM emp
WHERE dept = dept_in ;
* Returning Cursor - A cursor header that contains
a return clause

CURSOR emp_cur (dept_in [IN] NUMBER) IS
RETURN emp%ROWTYPE
SELECT *
FROM emp;


Hope so, above paragraphs explain cursors very well and in
details.

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of operators available in sql?

552


What are the properties of a transaction?

559


What is latest version of sql?

523


How do you remove duplicate records from a table?

509


What is the use of nvl function?

617






How to select unique records from a table?

568


Can a procedure in a package be overloaded?

544


How can I get the number of records affected by a stored procedure?

570


How long will it take to learn pl sql?

522


What is sql architecture?

557


How do I sort a table in sql?

591


What is Materialized View? In What Scenario we Use Materialized View?

8515


Is crud a cuss word?

544


What is difference between sql and mysql?

529


Can we insert data in view?

501