cursors in sql?

Posted on 2011-05-06
Last Modified: 2012-05-11
Dear Experts,

Please describe what is the purpose of the cursors in SQL, what is the necessity to write cursors with in the procedures, please give me a simple example.
Question by:haneef_nb
    LVL 76

    Expert Comment

    by:slightwv (䄆 Netminder)
    Is this also a homework/exam question?

    Please check the docs.  They describe it better than we can.

    The purpose is to move datasets around.  Think of a cursor as a collection of results from a select statement.

    You can pass them around and/or process them row by row in a loop.

    Examples are all over the place if you search for them.
    LVL 42

    Accepted Solution

    The SQL language works on sets and every row in the set is treated the same.  

    A cursor is a mechnism to step thru a set, one record at a time.  Then you can process each record individually.

    A set-wise insert:
    insert into table1
       select * from table2;

    A cursor insert:
    For r in (Select * from Table2)       <--this is a cursor
      insert into table2 values r;

    end loop;


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Title # Comments Views Activity
    jobsrunning 3 55
    Oracle to_char 21 52
    import data 5 47
    Create index on View 27 45
    This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
    Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
    This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
    Via a live example, show how to take different types of Oracle backups using RMAN.

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now