473,722 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Execute Immediate in UDF

In DB2 LUW 'till Version 9 it is not possible to execute dynamic SQL
in a UDF (at least as I understand it; maybe I'm just doing something
wrong). Is this planed to be included in Future Versions? Somebody has
an Idea for a workaround to this?

What I need to do: We have for different customers an individual
customer table, and we'd like a table UDF to return the records of a
customer table based on the ID of a customer. This would allow not to
have to generate dynamic SQL for joining the tables in the
application, but just to call a function which does this for us.

Any ideas or hints would be appreciated.

Regards,
Janick
Mar 2 '08 #1
2 2325
ja******@swissa sp.ch wrote:
In DB2 LUW 'till Version 9 it is not possible to execute dynamic SQL
in a UDF (at least as I understand it; maybe I'm just doing something
wrong). Is this planed to be included in Future Versions?
Future? Yes I can confirm something that fuzzily :-)
Somebody has an Idea for a workaround to this?
Create a procedure with the dynamic SQL in it.
Then CALL the procedure from the UDF.
Now a quick test reveals that PREPARE/EXECUTE is treated as MODIFIES SQL
DATA, so you may have to go with a TABLE UDF, since scalar UDF do not
support MODIFIES SQL DATA.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 2 '08 #2
On Mar 2, 10:52 pm, Serge Rielau <srie...@ca.ibm .comwrote:
jaber...@swissa sp.ch wrote:
In DB2 LUW 'till Version 9 it is not possible to execute dynamic SQL
in a UDF (at least as I understand it; maybe I'm just doing something
wrong). Is this planed to be included in Future Versions?

Future? Yes I can confirm something that fuzzily :-)
Somebody has an Idea for a workaround to this?

Create a procedure with the dynamic SQL in it.
Then CALL the procedure from the UDF.
Now a quick test reveals that PREPARE/EXECUTE is treated as MODIFIES SQL
DATA, so you may have to go with a TABLE UDF, since scalar UDF do not
support MODIFIES SQL DATA.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Thanks for the fast response Serge. That's pretty much what I figured
I'll have to do.
Good to know though it will once be simplified in the far future :)

Regards,
Janick
Mar 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
22392
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
28422
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'
2
7294
by: sultana | last post by:
I want to pass paramete in from caluse in a parameterized cursor & use this in Execute Immediate. Is it possible?
70
6200
kiss07
by: kiss07 | last post by:
Hi, i want 2 and 3 rd max salary in a table .i want a single query. please help.. Arun
1
2331
by: lakon15 | last post by:
Dear all, I'll try to convert from SQL server Store Procedure to DB2 Store Procedure. I've make SP under DB2 like this CREATE PROCEDURE GetSearchedRecords (pKeyWords VARCHAR(1000), pIsAll INTEGER, pIsExact INTEGER, pDateCondition INTEGER, pDateType INTEGER, ...
5
7772
by: umesh049 | last post by:
Hello, I want to delete all the date of all the table in a scheman. but i got error at execute immediate statement. can any body help me. thanks
3
7030
by: nghivo | last post by:
My environment DB2 9.1.4 on Sun OS I write a C embedded SQL to load data. I declare host vars as: EXEC SQL BEGIN DECLARE SECTION; SQL TYPE IS CLOB(599999) sqlStr; EXEC SQL END DECLARE SECTION;
3
6958
by: Rahul Babbar | last post by:
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
6
4435
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...
2
11149
by: eeriehunk | last post by:
Hi All, I was going through DBMS_SQL package when I tried to research on Dynamic SQL. I couldn't understand the necessity for this package since we can use EXECUTE IMMEDIATE to execute any DDL inside a PLSQL procedure. Why make things complicated using the PARSE procedure supplied with the DBMS_SQL package. Regards, Aj
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
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
9384
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
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8052
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
4502
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
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
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
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.