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

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

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.
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

A list of cursor examples:

If this isn't clear just post back and we can explain it in more detail.
Swadhin RaySenior Technical Engineer Commented:
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.