We help IT Professionals succeed at work.

Dynamic Cursor DB2

ajexpert
ajexpert asked
on
4,465 Views
Last Modified: 2012-06-21
Ok, here is the question.

I need define a cursor having select statement with dynamic where clause.

Here is the detailed requirement in points.

1.      Create a stored procedure with parameters which will be part of where clause of cursor in procedure definition/body.
2.      This SP will have the cursor a select statement with dynamic where clause.
3.      This stored procedure will be executed from a .bat file with parameters.


Please let me know how do I do this in DB2.

Sample code would be of great help
Comment
Watch Question

hi
i did not understand what exactly do you need when you say dynamic where clause
do you need
1) a where clause with unknown predicates, that is sometimes it will have where col1 = 1 and sometimes it will have where col2 = 1
2) a where clause with dynamic parameters, that is sometimes where col1 = 1 and sometimes where col1 = 2

thanks
plus
do you want it to be a sql procedure or a procedure using some other langauage such as java

Author

Commented:
Ok,
Here i rephrase the query.

I want a cursor for which a select statement can be build on run time.
This is very similar to REF CURSOR in ORACLE

Like there will be a SELECT statement with WHERE CLAUSE and I have to process this statement via CURSOR LOOP

I have searched something like PREPARE STAMENT, EXEC SQL should do the trick, but I am unable to compile in DB2 command center.

I hope my question is clear, If not let me know I will explain with example
post here the code you cant compile and the message you ger and i'll try to tell you whats wrong with it

Author

Commented:
OK...I found the solution...

I request EE Volunters to please close the question.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.