By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,813 Members | 1,236 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,813 IT Pros & Developers. It's quick & easy.

capturing the result from Execute Immediate

P: n/a
Hi,

I have the following doubt.

Suppose I use the execute immediate statement and the statement to be
executed is a Select statement from the sysibm.sysdummy1 table which
will always return me one row.
Further, i need to capture the result of the execute Immediate into a
variable of some data type and use it.

How can i achieve it.

Eg in a procedure

Set str = 'Select current timestamp from sysibm.sysdummy1'
Execute Immediate str;

So, if i want to capture the value returned in a variable of
appropriate data type, what could i do...
Thanks a lot.

Rahul Babbar
Feb 7 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Ian
Rahul Babbar wrote:
Hi,

I have the following doubt.

Suppose I use the execute immediate statement and the statement to be
executed is a Select statement from the sysibm.sysdummy1 table which
will always return me one row.
Further, i need to capture the result of the execute Immediate into a
variable of some data type and use it.

How can i achieve it.

Eg in a procedure

Set str = 'Select current timestamp from sysibm.sysdummy1'
Execute Immediate str;

So, if i want to capture the value returned in a variable of
appropriate data type, what could i do...
Use SELECT ... INTO:

select current timestamp into your_variable
from sysibm.sysdummy1

Please note, you don't need to do a query for this:

set your_variable = current timestamp;
Feb 7 '08 #2

P: n/a
In DB2 9.5 you can do SET ? = (SELECT .....)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 7 '08 #3

P: n/a
On Feb 7, 10:28 pm, Ian <ianb...@mobileaudio.comwrote:
Rahul Babbar wrote:
Hi,
I have the following doubt.
Suppose I use the execute immediate statement and the statement to be
executed is a Select statement from the sysibm.sysdummy1 table which
will always return me one row.
Further, i need to capture the result of the execute Immediate into a
variable of some data type and use it.
How can i achieve it.
Eg in a procedure
Set str = 'Select current timestamp from sysibm.sysdummy1'
Execute Immediate str;
So, if i want to capture the value returned in a variable of
appropriate data type, what could i do...

Use SELECT ... INTO:

select current timestamp into your_variable
from sysibm.sysdummy1

Please note, you don't need to do a query for this:

set your_variable = current timestamp;
Hi,

Select current timestamp from sysibm.sysdummy1 was a wrong example to
simplify the scenario.

I have to execute the query dynamically.

So, it's something like, I have to use execute immediate(or any other
command which executes it dynamically) and then capture the result
into a variable.

set var = Execute Immediate(str)

doesn't seem to work...Further, it seems that doing a select in
Execute Immediate is not allowed(i don't exactly remember the error
code for this), but this is my requirement.
I have to somehow do dynamic select, may be by using something other
than Execute Immediate.

What could i do?

Thanks a lot

Rahul
Feb 8 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.