File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes looping in stored procedure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "looping in stored procedure" Watch "looping in stored procedure" New topic

looping in stored procedure

san krish
Ranch Hand

Joined: Aug 11, 2010
Posts: 41
I have a query like this,

select email as vEmail from users where id in (217211,217521,217641)

Now this query returns 3 email id's. I have to loop through the vEmail and assign them to different local variables in stored procedures.

like email for 217211 is stored in vEmail1
217521 in vEmail2
217641 in vEmail3

Can somehow help me in this looping?
Tom Reilly

Joined: Jun 01, 2010
Posts: 618
Have you looked at using a cursor?
san krish
Ranch Hand

Joined: Aug 11, 2010
Posts: 41
No.I just want to use while or for loop if that works. Is it possible?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

First you should mention what language you're writing this stored procedure in. (It probably isn't Java.) And second you should explain how you expect to figure out which of the three e-mail addresses you get in that result set belongs to which ID, given that you don't have the ID in the result set.
san krish
Ranch Hand

Joined: Aug 11, 2010
Posts: 41
Hi Im using Java.
And my result set contains all the 3 email id's.
whatever i give in the 'IN' clause, i want to name it acc as email1, email2, email3.
I agree. Here's the link:
subject: looping in stored procedure
It's not a secret anymore!