IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Difference between CURSOR and Select *


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
murleedhar

New User


Joined: 10 Mar 2005
Posts: 5
Location: bangalore

PostPosted: Wed Jun 08, 2005 3:04 pm
Reply with quote

we will use cursor to fetch more than one single row, then what is select * from table name.. what is the difference b/n these two
Back to top
View user's profile Send private message
ssowjanya

New User


Joined: 29 Apr 2005
Posts: 13

PostPosted: Wed Jun 08, 2005 4:23 pm
Reply with quote

Hi murleedhar,
While programming in db2-cobol multiple rows cannot be retrieved at a time. so we use cursors to retrieve multiple rows.
Back to top
View user's profile Send private message
murleedhar

New User


Joined: 10 Mar 2005
Posts: 5
Location: bangalore

PostPosted: Wed Jun 08, 2005 4:39 pm
Reply with quote

hi, yes u r right. then wht does select * do??
Back to top
View user's profile Send private message
Deepa.m

New User


Joined: 28 Apr 2005
Posts: 99

PostPosted: Wed Jun 08, 2005 5:51 pm
Reply with quote

Select * displays the rows matching the condition but can't be used in programs to process the records.

but if you want to fetch each row in the application program you have to use cursor and process records one by one.
Back to top
View user's profile Send private message
Pushpak

New User


Joined: 06 May 2005
Posts: 18

PostPosted: Thu Jun 09, 2005 1:48 pm
Reply with quote

Hi

# SELECT * - will return results as a SET, if it finds more than one row in a table.

If your requirement is to get only one row no matter how may row SELECT * returning, then in that case you may use SELECT * & handle sql code -811 in your application program. But if you want to process all the records then you have to use CURSOR in your application program.

CURSOR is not any sql/query. SELECT * will return all the records & CURSOR will put all these records in a buffer & will make available to the application program one by one.
Back to top
View user's profile Send private message
j_prameela2000

New User


Joined: 01 Jun 2005
Posts: 28
Location: Chennai

PostPosted: Fri Jun 10, 2005 11:34 am
Reply with quote

We cannot given Select * in Embedded sql ie. Within Exec SQL and End SQL. In embedded sql which is written within COBOL-DB2 program, SELECT statement can retrieve only one row at a time. So inorder to multiple rows we make use of cursor which retrieves multiple rows from a table. Select * can be given in SPUFI to retrieve all the rows in the table. If this is wrong, please correct me.
Back to top
View user's profile Send private message
Pushpak

New User


Joined: 06 May 2005
Posts: 18

PostPosted: Fri Jun 10, 2005 2:43 pm
Reply with quote

Hi Prameela,

I am using DB2 Version V7, I have tested SELECT * query (EXEC SQL - END-EXEC) in Cobol-DB2 application program & it is working fine.

I am not sure whether it works with prior versions of DB2 or not, but DB2 Ver 7 & onwards, it is working fine.

Pushpak.
Back to top
View user's profile Send private message
j_prameela2000

New User


Joined: 01 Jun 2005
Posts: 28
Location: Chennai

PostPosted: Mon Jun 13, 2005 10:44 am
Reply with quote

Hi Pushpak,

Select * in Embedded SQl can be given but I have a doubt whether it retrieves multiple rows or it retrieves single row at a time based on the condition. Please clarify my doubt. When you give Select * from table where <condition> will retrieve all the rows whichever satisfies the condition in SPUFI. But same way, in Embedded SQL using CURSOR you can retrieve multiple rows and can access the record one by one using Select * in embedded sql. Please tell me whether i am correct or wrong.
Back to top
View user's profile Send private message
j_prameela2000

New User


Joined: 01 Jun 2005
Posts: 28
Location: Chennai

PostPosted: Mon Jun 13, 2005 2:14 pm
Reply with quote

Hi,

Select * means retrieving all the fields in a table. Where as Cursor selects only selected fields from a table. I hope this is correct. If wrong please correct me.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Timestamp difference and its average ... DB2 11
No new posts SELECT from data change table DB2 5
No new posts Select two different counts from SQL... DB2 6
No new posts Difference when accessing dataset in ... JCL & VSAM 7
Search our Forums:

Back to Top