• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

cursors in sql?

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.
0
haneef_nb
Asked:
haneef_nb
1 Solution
 
slightwv (䄆 Netminder) Commented:
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.
0
 
dqmqCommented:
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;
Loop;

end loop;



0
 
haneef_nbAuthor Commented:
thanks
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now