473,395 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 2298
ja******@swissasp.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...@swissasp.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
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...
2
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
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
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), ...
5
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
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...
3
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...
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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...
0
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...

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.