What is cursor

Answers were Sorted based on User's Feedback



What is cursor..

Answer / tripti gour

In order to process a sql statements 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 the select
statement, a pointer to the parsed representation of the
statement, and in the case of a query, the active set,
which is the set of rows returned by the query.
A cursor is a handle or pointer to the context area.
Sql cursor attributes are:
1. SQL%ROWCOUNT: number of rows affected by the most recent
sql statement (an integer value).
2. SQL%FOUND: Boolean attribute that evaluates to TRUE if
the most recent SQL statement affects one or more rows.
3. SQL%NOTFOUND: Boolean attribute that evaluates to true if
the most recent SQL statement does not affects any rows.
4. SQL%ISOPEN: always evaluates to false because pl/sql
closes implicit cursors immediately after they are executed.

Cursor Types:
1. Implicit cursor
2. Explicit Cursor
3. REF cursor
4. Parametrized cursor
5. FOR LOOP Cursor

Implicit cursor:

a.Are opened implicitly by oracle whenever a DML or select
statement is executed.
b.Opened, fetched, closes internally.
c.Un-named cursors
d.Attributes: sql%isopen, sql%found, sql%notfound, sql%rowcount.

Explicit cursor

•Are declared and opened explicitly by developers to
manipulate multiple rows returned by queries one by one.
•Manually we have to declare, open, fetch, and close it.
•Name given to a context area.
•Attributes: cur_name%isopen, cur_name%found,
ur_name%notfound, cur_name%rowcount.

REF CURSOR EXAMPLE

declare
type t1 is ref cursor;
v1 t1;
begin
open v1 for select * from inv;
open v1 for select * from inv2;
end;

Parameterized cursor:

We can pass parameters for cursor as like procedures and
functions.
Syntax: cursor cursor_name[parameter_name datatype] is
select statement;
the advantage of parameterized cursor is, a single cursor
can be opened and closed several times in a block, returning
different active set in each occasion.
Note: formal parameters should not be mentioned with data type

Thanks,
Tripti

Is This Answer Correct ?    10 Yes 0 No

What is cursor..

Answer / ramdeep garg

A cursor is a SELECT statement that is defined within the
declaration section of your PLSQL code. We'll take a look
at three different syntaxes for cursors.

Cursor without parameters (simplest)
The basic syntax for a cursor without parameters is:

CURSOR cursor_name
IS
SELECT_statement;



For example, you could define a cursor called c1 as below.

CURSOR c1
IS
SELECT course_number
from courses_tbl
where course_name = name_in;

The result set of this cursor is all course_numbers whose
course_name matches the variable called name_in.



Below is a function that uses this cursor.

CREATE OR REPLACE Function FindCourse
( name_in IN varchar2 )
RETURN number
IS
cnumber number;

CURSOR c1
IS
SELECT course_number
from courses_tbl
where course_name = name_in;

BEGIN

open c1;
fetch c1 into cnumber;

if c1%notfound then
cnumber := 9999;
end if;

close c1;

RETURN cnumber;

END;

Is This Answer Correct ?    7 Yes 1 No

What is cursor..

Answer / vipin kumar ( m.c.a)

Cursor is a private SQL work area to perform an action using
PL/SQL statement. DBA allocate the memory space to the
objects that is area is called the cursor.
Cursor has two types-
1. Implicit cursor:- means predefine cursor.
2. Explicit cursor:- means created by the user or programmer.

Is This Answer Correct ?    2 Yes 1 No

What is cursor..

Answer / harsha vardhan reddy

CURSOR is a temporary workspace area used to hold
transaction data.

It is valid in PLSQL only.

It is not stored in database.

It cannot be reuse.

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More Oracle General Interview Questions

What are Schema Objects ?

2 Answers  


Explain what are the characteristics of data files?

0 Answers  


What is instant client oracle?

0 Answers  


State and explain about oracle instance?

0 Answers  


what is the difference between UNION AND UNIONALL

4 Answers  






I am using an Oracle 8i Database my data contains Clob data. I am using toad version 7.6 i am able to get the data in toad but unable to extract the data in excel.when trying to extract the data into the excel the toad error says out of memory. Can any body please help me to extract the data through the same toad version. Thanks in advance

0 Answers   Cisco,


Her departmandaki isçilerden empno' su ikinci sirada olan isçilerin empno, deptno, hiredate, sira_no bigilerini döndüren sorguyu yaziniz?

0 Answers  


How to create an oracle database manually?

0 Answers  


What is difference between SQL and SQL*PLUS?

1 Answers  


how to clone 9i Database on to 10g Database.

0 Answers  


What happens if variable names collide with table/column names?

0 Answers  


What is the data pump import utility?

0 Answers  


Categories
  • Oracle General Interview Questions Oracle General (1789)
  • Oracle DBA (Database Administration) Interview Questions Oracle DBA (Database Administration) (261)
  • Oracle Call Interface (OCI) Interview Questions Oracle Call Interface (OCI) (10)
  • Oracle Architecture Interview Questions Oracle Architecture (90)
  • Oracle Security Interview Questions Oracle Security (38)
  • Oracle Forms Reports Interview Questions Oracle Forms Reports (510)
  • Oracle Data Integrator (ODI) Interview Questions Oracle Data Integrator (ODI) (120)
  • Oracle ETL Interview Questions Oracle ETL (15)
  • Oracle RAC Interview Questions Oracle RAC (93)
  • Oracle D2K Interview Questions Oracle D2K (72)
  • Oracle AllOther Interview Questions Oracle AllOther (241)