What is cursor

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the max number of columns in an oracle table?

753


How to call a sub procedure?

842


What is the difference between online and offline backups?

769


what is the difference between data migration and production migration.

2079


What is a proxy class?

768


How to run queries on external tables?

809


What is an oracle data file?

862


How to create a new table by selecting rows from another table?

854


What happens to the current transaction if the session is ended?

838


What is an oracle recycle bin?

743


How to create a table in a specific tablespace?

759


Differentiate between translate and replace?

836


What are the original export and import utilities?

790


What is a cursor in oracle?

857


What operating systems are supported by oracle database 10g xe?

820