Cursor Used with LOOP/WHILE/REPEAT

I read as folows but not clear on this


Cursor Used with LOOP/WHILE/REPEAT to process a
collection of records (Result set) returned by
SELECT


Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
LVL 7
gudii9Asked:
Who is Participating?
 
brijesh_chauhanMySQL DBACommented:
Hi,

Curosor Is Nothing But The Pointer To The Dataset.. That Will Intially Pointing To The First Record.

To Use Cursor You Have To Follow These Many Steps.
1. Declare Cursor
2. Open Cursor
3. Fetch Cursor
4. Close Cursor

Here Is Simple  Demo.

Declare curse-name (Eg cur1) CURSOR select query(Eg select id,name from table);

open cur1;

fetch cur1 into a,b; (a and b are temporary variables)

Now What Happens suppose that ur select query has 100 records.
so these 100 recoreds are right now stored in a and b. (id in a AND name in b).

now you can process these records individually by the repeat or any other loops.

this is the main use of the cursor
once this will done close the cursor with

close cur1;

Hope This Would Help.
0
 
slightwv (䄆 Netminder) Commented:
There are a ton of examples out there on cursor loops and a couple ways to declare a cursor (explicit or implicit).

The online docs have many examples:  Example 6-6 FETCH Statements Inside LOOP Statements
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/static.htm#BABCFDJE


A list of cursor examples:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/fetch_statement.htm#CJAHEFJJ

If this isn't clear just post back and we can explain it in more detail.
0
 
Swadhin RaySenior Technical Engineer Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.