472,958 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

capturing the result from Execute Immediate

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
3 6901
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
In DB2 9.5 you can do SET ? = (SELECT .....)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 7 '08 #3
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: -------------------------------------...
2
by: michi | last post by:
Hello there... Can anybody tell me what is the difference when I excecute a sql statement within pl sql with/without "execute immediate" statement Thanks Michi :)
4
by: finlma | last post by:
I'm trying to run an EXECUTE IMMEDIATE within a PL/SQL if loop but it doesn't work for me. I'm trying to create a column conditionally but it doesn't work. It fails because there are apostrophes...
3
by: Agoston Bejo | last post by:
I am looking for the PL/SQL equivalent of the VBScript Exec and/or Eval functions, i.e. I want to be able to dynamically create a statement, then execute it in the current PL/SQL context, e.g. ...
1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
2
by: GS | last post by:
How can one avoid capturing leading empty or blank lines? the data I deal with look like this "will be paid on the dates you specified. xyz supplier amount: $100.52 when: September 07,...
10
by: trakal | last post by:
Hello everybody, i have a problem that i don't know how to solve it. I created a procedure like this: create or replace PROCEDURE Employee_LoadById ( p_Id NVARCHAR2 ) AS
6
by: Oliver | last post by:
I'm fairly new to DB2. I have been assigned to build a delete trigger that finds the data type of each of the table's fields so that the trigger can then build a string consisting of OLD values...
1
ddtpmyra
by: ddtpmyra | last post by:
how can I capture the query result in PHP? I have two queries below: # Fetch the file information $query ="update filestorage set approved ='Y' where FileID = {$id}"; $query1 ="select...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.