Cursor Used with LOOP/WHILE/REPEAT

Posted on 2012-09-20
Last Modified: 2012-10-01
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
Question by:gudii9
    LVL 76

    Assisted Solution

    by:slightwv (䄆 Netminder)
    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.
    LVL 16

    Assisted Solution

    by:Swadhin Ray
    LVL 2

    Accepted Solution


    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.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Tracking a Database Lock - SQL 2014 10 31
    Php Sql Query 7 20
    MySQL - Limit or Top Records 15 26
    Oracle Database Upgrade 13 26
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
    This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
    This video shows how to recover a database from a user managed backup

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now