View previous topic :: View next topic
|
Author |
Message |
shrikanth_m Currently Banned New User
Joined: 19 Jan 2007 Posts: 5 Location: bangalore
|
|
|
|
why select * retrieve only one row, where as cursor retrieves multiple rows? is there any specific reason for that? can some body help me out !!
Aprreciate help from anyone!
Thanks
Shrikanth! |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
As far as I know, "*" just retrieves all columns, it is the "where" that retrieves the rows.
I can't access the command reference (IBM's site is having a "Internal Server Error") to see what kind of retrieval occurs without a "where" clause - or even if that is allowed. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
why select * retrieve only one row, where as cursor retrieves multiple rows? is there any specific reason for that? |
The reason is because that is the way DB2 is implemented. To "scroll" thru multiple rows in your program, you use a cursor. |
|
Back to top |
|
|
sachin_star3 Warnings : 1 New User
Joined: 30 Sep 2006 Posts: 78 Location: pune
|
|
|
|
shrikanth_m wrote: |
why select * retrieve only one row, where as cursor retrieves multiple rows? is there any specific reason for that? can some body help me out !!
Aprreciate help from anyone!
Thanks
Shrikanth! |
======================================
HI SHRIKANT
ANSWER:
THE CURSOR IS A CONTROL STRUCTURE , USING CURSOR
THREE STEP: 1] OPEN CUSOR:- IT LOCATE THE POINTER TO FIRST ROW AND IF GROUP BY OR ORDER BY USED THEN IT BUILTS THE RESULTANT TABLE ALSO
2] FETCH CURSOR: IT FETCHES THE ROW 1 BY ONE FROM RESULTANT TABLE
3] CLOSE CURSOR
SO WHEN CURSOR IS FIRST ROW FETCH CURSOR SHOW IT THNIT FETCHES SECOND AND GOING ON --------- BUT WE GET ALL ROWS IN SPPOL AREA BECAUSE I. E FINAL RESULT
AND YOUR QUESTION IS WHY NOT POSSIBLE WITH SELECT*
BECAUSE IT NOT SAVE AND LOCATE THE POSITION AND THERE NO STEPS SO YOU CANT NOT GET RESULT
I THINK IN ABOVE DISCUSSION ONE QUESTION DEFINETLY ARISE YOUR MIND THAT WHY IT IS POSSIBLE IN SPUFI,QMF?
ANSWER:
BECAUSE QMF,SPUFI DYANMICALLY RUN THE SQL QUERY--SET AT TIME
BUT USING FILE MEANS YOU HAVE TO FOLLOW THE BATCH PROCEESING RULE SO IN BATCH THE READ A RECORD/ROW AT A TIME
SO IT IS NOT POSSIBLE WITH SELECT * BECAUSE IT WORK FOR SET AT TIME
SO YOU NEED PALNING SO CURSOR COMES IN PICTURE
I HAVE MENTION THE DETAILS IN ABOVE PARAGRAPH.
SHURE!
FROM- SACHIN BORASE
PUNE
***EMail ID REMOVED... Use CODE tag to include mail id***
---------------------------------------------------------------------------- |
|
Back to top |
|
|
sundar28
New User
Joined: 30 Jul 2005 Posts: 11 Location: Mysore
|
|
|
|
Quote: |
why select * retrieve only one row, where as cursor retrieves multiple rows? is there any specific reason for that? |
DB2 operates on tables and results in another table.
The result table may consist of one are any number of rows depending on the "WHERE" clause.
The COBOL compiler can not handle the table as a single data element.
It can process only one row at a time.
Cursors are used to feed COBOL one row at a time.
It is the inability of the COBOL that we need Cursors.
Note: COBOL* is a 3rd Generation Language and SQL is 4th generation language.
*It is not only COBOL but also other languages like C, C++ |
|
Back to top |
|
|
ashish_setia Currently Banned New User
Joined: 19 Jan 2007 Posts: 3 Location: noida
|
|
|
|
hey,
this is quit simple actually COBOL is a record level programming language which actually process only one record at a time so if ur trying to get more than one record from database using select * ,,,, it can only retrieve u asingle row at atime..
about using cursor..
actually when we declare a cursor and then open it actually make RESULT TABLE (which is having all the records u have selected using SELECt *) and put that table in main memory (not visible to us).
and cursor will do the same thing that cobol program was doing ..
selecting one roe at a time but it can dynamically go to thr result table again a nd again an willa ctually write all ur result of SELECT * into the spool or into the file..
i suppose the concept would b a bit clear to u now
Ashish setia
shrikanth_m wrote: |
why select * retrieve only one row, where as cursor retrieves multiple rows? is there any specific reason for that? can some body help me out !!
Aprreciate help from anyone!
Thanks
Shrikanth! |
|
|
Back to top |
|
|
|