Cursor
Posted Date Unknown stephin Francis Antony 1 Comment

What is the use of cursor? How to use cursor in our program?

See All Responses Below...
Author
Message Rating
Posted on: 25/05/2012

Cursor is used to access the records of a table one by one and can do theoperation.

Suppose you've a table named 'Person'as the following:

ID

Name

Age

1

aa

20

2

bb

25

3

cc

30

4

dd

22

then, you can create a CURSOR (with Declare, Open, Fetch and Close) asfollows for retrieving person name one by one:

DECLARE Names varchar(10);
DECLARE CursorTest CURSOR FOR SELECT Name from Person;
OPEN CursorTest ;
FETCH   CursorTest into Names ;
SELECT  Names ;
CLOSE  CursorTest ;

You can create it in a stored procedure and can call the procedure to executeit. So the final result will be as follows:

aa

bb

cc

dd

 

Please Login to Post Your Comments
Name (Max. 100 characters)
Please post your comments here
Select Language
Comments
   Design  HTML
Attach File(Max. Size: 2 MB)
A few simple rules when posting your Comments,
  1. Please post only answers relevant to the topic of discussion.
  2. Please dont misuse this site or do not be abusive, offensive, inappropriate,harass anyone on the boards or post ads or spam. Doing so will delete your inappropriate messages and will block or delete your account on this site. 

TekTipsDownload
GateExam
Academic Projects
TekTipsExperts



 
Site optimized for IE7, 1280 X 768 and above. Copyright © 2010 - 2018 KTS InfoTech
Site Developed Using KTS WebCloud