View previous topic :: View next topic |
Author |
Message |
hisabarish Beginner
Joined: 21 Jun 2005 Posts: 38 Topics: 11
|
Posted: Tue Jun 21, 2005 4:01 am Post subject: Doubt in Cursor? |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12384 Topics: 75 Location: San Jose
|
Posted: Tue Jun 21, 2005 4:52 am Post subject: |
|
|
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 |
|
 |
bauer Intermediate
Joined: 10 Oct 2003 Posts: 317 Topics: 50 Location: Germany
|
Posted: Wed Jun 22, 2005 1:05 am Post subject: |
|
|
hisabarish,
the better way to get the number of records is select count(*) from ..... where ....
regards,
bauer |
|
Back to top |
|
 |
hisabarish Beginner
Joined: 21 Jun 2005 Posts: 38 Topics: 11
|
Posted: Wed Jun 22, 2005 6:56 am Post subject: |
|
|
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 |
|
 |
bauer Intermediate
Joined: 10 Oct 2003 Posts: 317 Topics: 50 Location: Germany
|
Posted: Wed Jun 22, 2005 7:38 am Post subject: |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12384 Topics: 75 Location: San Jose
|
Posted: Wed Jun 22, 2005 7:52 am Post subject: |
|
|
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 |
|
 |
hisabarish Beginner
Joined: 21 Jun 2005 Posts: 38 Topics: 11
|
Posted: Wed Jun 22, 2005 7:55 am Post subject: |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12384 Topics: 75 Location: San Jose
|
Posted: Wed Jun 22, 2005 8:12 am Post subject: |
|
|
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 |
|
 |
bauer Intermediate
Joined: 10 Oct 2003 Posts: 317 Topics: 50 Location: Germany
|
Posted: Wed Jun 22, 2005 8:19 am Post subject: |
|
|
Hi kolusu,
perfect confusion ?!
regards,
bauer |
|
Back to top |
|
 |
SureshKumar Intermediate
Joined: 23 Jan 2003 Posts: 211 Topics: 21
|
Posted: Wed Jun 22, 2005 10:48 am Post subject: |
|
|
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 |
|
 |
hisabarish Beginner
Joined: 21 Jun 2005 Posts: 38 Topics: 11
|
Posted: Thu Jun 23, 2005 8:27 am Post subject: |
|
|
Hi suresh and rest of dears,
Thanx a lot for your answers. Now i am clear about that question. _________________ Sabari
Madras |
|
Back to top |
|
 |
|
|