If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Declare cursor with IN function in the where clause

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-18-04, 16:59
berubea berubea is offline
Registered User
 
Join Date: Feb 2004
Location: Montreal
Posts: 2
Lightbulb Declare cursor with IN function in the where clause

I have been looking over don't find answer yet !!

I need to declare a cursor wit an IN function in the where clause
I do I declare my Cobol variable ....

Ex:

var-1 pic x(80).


exec sql declare cursor for
select empno
from emptable
where empname in (:var-1)

is this ok ???
I do I string all different values : value1, value2, value3 ....
or other way ??

please help !!
Reply With Quote
  #2 (permalink)  
Old 02-18-04, 17:14
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Your post is not totally clear to me. As written the cursor looks fine. But I don't know what you are trying to do.

Do you mean?

declare cursor for
select empno
from emptable
where empname in (:var-1, :var2, :var3)

But if you try to put several multiple values all inside of :var1, it will not work the way you want.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 02-18-04, 17:17
berubea berubea is offline
Registered User
 
Join Date: Feb 2004
Location: Montreal
Posts: 2
OK but If I have a non determine number of value in the IN clause ??

Is that a limitation

empname in (:var1, :var2, :var3 .....


thanks for your answer
Reply With Quote
  #4 (permalink)  
Old 02-18-04, 18:32
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
This issue has been discussed before. There seems to be some limit to the number of variables in an IN, but I don't know what it is, and you never indicated the details needed about your environment which are requested in MUST READ BEFORE POSTING. Even before the limit is reached, there may be performance degradation if the list is very long.

If you have static SQL, you have to code all the host variables ahead of time. If you use dynamic SQL, you can build the statement on the fly with the desired number of variables in the where clause.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On