MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Doubt in Cursor?

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
hisabarish
Beginner


Joined: 21 Jun 2005
Posts: 38
Topics: 11

PostPosted: Tue Jun 21, 2005 4:01 am    Post subject: Doubt in Cursor? Reply with quote

I have a table emp - fileds are eno,ename,sal,email.
Now i am declare a cursor like that

Declare emp_cur cursor as select eno,ename,email from emp
where eno = eno.

Now i want to know how many records will be taken in the cursor.
_________________
Sabari
Madras
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12384
Topics: 75
Location: San Jose

PostPosted: Tue Jun 21, 2005 4:52 am    Post subject: Reply with quote

hisabarish,

A couple of errors in your cursor declaration. You define a CURSOR "FOR" the select stmt but not "AS". You need to use host variables in your where clause. Unless you move values to the host variables your cursor will NOT fetch any records.

ex:
Code:

Declare emp_cur cursor for
 select eno,ename,email
   from emp
  where eno = :eno


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
bauer
Intermediate


Joined: 10 Oct 2003
Posts: 317
Topics: 50
Location: Germany

PostPosted: Wed Jun 22, 2005 1:05 am    Post subject: Reply with quote

hisabarish,

the better way to get the number of records is select count(*) from ..... where ....

regards,
bauer
Back to top
View user's profile Send private message
hisabarish
Beginner


Joined: 21 Jun 2005
Posts: 38
Topics: 11

PostPosted: Wed Jun 22, 2005 6:56 am    Post subject: Reply with quote

hi Kolusu and
bauer

Thankx for ur reply and point out my error. My doubt is suppose i am selecting a cursor in where clause i am mentioning the same column name ie.,

Declare curname cursor for select eno, email from emp where eno = eno.

Note: eno is a column name of a table. I am not using hostvariable. in the where clause.

How many records will be store in the Cursor. Pls. revert me
_________________
Sabari
Madras
Back to top
View user's profile Send private message
bauer
Intermediate


Joined: 10 Oct 2003
Posts: 317
Topics: 50
Location: Germany

PostPosted: Wed Jun 22, 2005 7:38 am    Post subject: Reply with quote

Hi,

your request is the number of rows in table (or view) EMP ? Is this correct ?

If so, code select count(*) from emp.

I'm not sure about your request.

regards,
bauer
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12384
Topics: 75
Location: San Jose

PostPosted: Wed Jun 22, 2005 7:52 am    Post subject: Reply with quote

Quote:

Note: eno is a column name of a table. I am not using hostvariable. in the where clause.
How many records will be store in the Cursor. Pls. revert me


Hisabarish,

Once again you CANNOT define a cursor without host-variables programmatically unless you are joining the table to itself. You need to get your basics right about declaring cursors in a program. Please go thru this link

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNAPH11/CCONTENTS?DT=20010710165542

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
hisabarish
Beginner


Joined: 21 Jun 2005
Posts: 38
Topics: 11

PostPosted: Wed Jun 22, 2005 7:55 am    Post subject: Reply with quote

Hi bauer,

Thankx for ur answer. My question is you have a table Emp. The fields are Eno, Ename and Email.
EMP
eno ename email.
1 X abc@yahoo
2 Y XX@rediff
3 K kk@sify
4 m mm@kal.com

Now you have 4 records in the Emp Table. In Embedded Sql u create a cursor , like

Exec Sql
Declare Ecur Cursor for select eno, email from Emp where eno = eno.
End-exec

Okay what is the result of this Ecur. How many records will be stored in the Ecur. Pls. revert me.
_________________
Sabari
Madras
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12384
Topics: 75
Location: San Jose

PostPosted: Wed Jun 22, 2005 8:12 am    Post subject: Reply with quote

hisabarish,

You are going in circles dude . Do you even read the posts clearly? Please check my prior post.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
bauer
Intermediate


Joined: 10 Oct 2003
Posts: 317
Topics: 50
Location: Germany

PostPosted: Wed Jun 22, 2005 8:19 am    Post subject: Reply with quote

Hi kolusu,

perfect confusion ?!

regards,
bauer
Back to top
View user's profile Send private message
SureshKumar
Intermediate


Joined: 23 Jan 2003
Posts: 211
Topics: 21

PostPosted: Wed Jun 22, 2005 10:48 am    Post subject: Reply with quote

hisabarish,
' How many records will be stored in the Ecur' you may as well test it - there will be 4 rows. But the point being made is why 'where eno = eno '. This is redundant, however your query will work. If you need to know the number of rows then use COUNT(*) and if you need other data along with it you will have to use GROUP BY. Since its a temp table, probably is it a distributed request ? which case you may have other options to get the count. Thanks
Back to top
View user's profile Send private message
hisabarish
Beginner


Joined: 21 Jun 2005
Posts: 38
Topics: 11

PostPosted: Thu Jun 23, 2005 8:27 am    Post subject: Reply with quote

Hi suresh and rest of dears,

Thanx a lot for your answers. Now i am clear about that question.
_________________
Sabari
Madras
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group