473,756 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.sysdummy 1 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.sysdummy 1'
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 6962
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.sysdummy 1 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.sysdummy 1'
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.sysdummy 1

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...@mobile audio.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.sysdummy 1 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.sysdummy 1'
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.sysdummy 1

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

set your_variable = current timestamp;
Hi,

Select current timestamp from sysibm.sysdummy 1 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
8134
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: ------------------------------------- test3.pl ------------------------------------- print "PERL Hello from Perl! (plain print)<br>\n"; print STDERR "PERL This is text sent to STDERR<br>\n"; $output="PERL Some output:<br>\n"; for ($i=0; $i<5; $i++) {
2
22395
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
28424
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 within the statement. How do I override the apostrophe? DECLARE cCount NUMBER; BEGIN SELECT count(*) INTO cCount FROM all_tab_columns WHERE owner = 'Owner'
3
20400
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. declare x integer := 5; begin ExecuteStatement('x := 10'); dbms_output.put_line(x); -- should put "10" if EvaluateExpression('x*2 = 20') then
1
5387
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 application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component for this, and a test application for the component. It allows me to specify a command to execute,...
2
2816
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, 2007 reference #: 0415 from: operating account
10
4540
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
4438
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 pre-wrapped in quote marks as needed. The deleted record's field values, all strung together as a single string, would then be inserted into a single archiving table (an architecture I inherited and cannot change). I've got the trigger doing...
1
1755
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 members.email from members, filestorage where filestorage.author = members.username and FileID = {$id}" ; then execute the query using command below: $result = @mysql_query($query) or die("Error! Query failed: <pre>". mysql_error($dbLink)...
0
9271
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10031
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9708
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.