473,385 Members | 1,337 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,385 software developers and data experts.

DB2 UDF create temporary table

Please find the code for creating a temporary table and access it in UDF functions.
While we do this we obtain a compile time error stating "A declared temporary table cannot be used in the given context."

Expand|Select|Wrap|Line Numbers
  1. CODE:
  2.  
  3. DECLARE GLOBAL TEMPORARY TABLE 
  4.         SESSION.TEMP (id INT, data VARCHAR(10))
  5.         ON COMMIT PRESERVE ROWS;
  6.  
  7.  ----------------------------- Commands Entered ------------------------------
  8.  
  9. CREATE FUNCTION fn_DocumentCount2 (v_GroupID CHAR(16) FOR BIT DATA )
  10. RETURNS INTEGER
  11.  
  12. LANGUAGE SQL
  13.  
  14. BEGIN ATOMIC
  15.  
  16.     DECLARE v_documentcount INTEGER;   
  17.  
  18.     delete from  SESSION.TEMP;
  19.  
  20.     RETURN 10;
  21.  
  22. END!
  23.  
  24. ERROR: 
  25.  
  26. SQL0526N  The requested function does not apply to declared temporary tables.
  27.  
  28. Explanation: 
  29.  
  30. A declared temporary table cannot be used in the given context.
Can we create a temporary table in udf ?
Apr 12 '08 #1
1 5297
docdiesel
297 Expert 100+
Hi,

please use code tags when posting code. In your sample you're creating a function which is a permanent object, while the global temp table will vanish after disconnect. So if the function is getting called sometime it cannot be sure if a new global temp table SESSION.TEMP has been created during the session or not, while the latter case would lead to an error. That's why DB2 acts somewhat foresighted and won't let you mix this.

Regards,

Bernd
Apr 12 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ezra epstein | last post by:
I found a post about something similar in an older release: http://archives.postgresql.org/pgsql-bugs/2002-08/msg00151.php Here's the issue. Inside a function I'm calling CREATE LOCAL TEMPORARY...
4
by: maricel | last post by:
Could someone confirm which tablespace is being used when running ALTER & CREATE INDEX. Is it the tempspace or the tablespace where the table resides? Many thanks, maricel
3
by: Wiggy | last post by:
Hi, It's probably easiest if I describe what I'm trying to do: I have several tables I want to base a query on. In addition I have some dynamic data that I want to join against that consists...
12
by: Doug Bell | last post by:
Hi, I am having problems trying to create a (temporary) DataTable from a selection from a DataGrid (dgOrders). dtOrdDetails is declared as a Public DataTable Sub is: Dim stFilter as String...
6
by: Peter Nurse | last post by:
For reasons that are not relevant (though I explain them below *), I want, for all my users whatever privelige level, an SP which creates and inserts into a temporary table and then another SP...
0
by: mktilu | last post by:
hi can any one give me a example to create temporary table in Stored procedure during run time and then delete the temporary table at the end of the stored procedure .its argent
2
by: prakashwadhwani | last post by:
I have an app with a Front End and a Back-End. My date field is INV_DATE I would like to copy all data with year(inv_date) 2005 to a temp table in both, the front end & the back end. How...
9
by: DottingTheNet | last post by:
help plz!! when i try to cretae a table in a procedure like create procedure blah is begin create table..... ...... end;
3
by: DeanL | last post by:
Hi guys, Does anyone know of a way to create multiple tables using information stored in one table? I have a table with 4 columns (TableName, ColumnName, DataType, DataSize) and wanted to know...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.