If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > creating a temporary table and access it in UDF functions

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-11-08, 11:40
kamal_001 kamal_001 is offline
Registered User
 
Join Date: Apr 2008
Posts: 2
creating a temporary table and access it in UDF functions

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."

CODE:

DECLARE GLOBAL TEMPORARY TABLE

SESSION.TEMP (id INT, data VARCHAR(10))

ON COMMIT PRESERVE ROWS;

----------------------------- Commands Entered ------------------------------

CREATE FUNCTION fn_DocumentCount2 (v_GroupID CHAR(16) FOR BIT DATA )

RETURNS INTEGER

LANGUAGE SQL

BEGIN ATOMIC

DECLARE v_documentcount INTEGER;



delete from SESSION.TEMP;

RETURN 10;

END!

ERROR:

SQL0526N The requested function does not apply to declared temporary tables.


Explanation:

A declared temporary table cannot be used in the given context

could you please tell me how do we resolve this error?
Reply With Quote
  #2 (permalink)  
Old 04-11-08, 13:16
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
As the error indicates, you cannot use a global temporary table in a UDF.

Andy
Reply With Quote
  #3 (permalink)  
Old 04-11-08, 13:28
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
As a work-around, you can put the DGTT statement into a stored procedure along with all processing on the DGTT and then call this procedure from a UDF.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #4 (permalink)  
Old 04-12-08, 07:01
kamal_001 kamal_001 is offline
Registered User
 
Join Date: Apr 2008
Posts: 2
Hi Folks,

Thanks for your timely response, could you please tell me how do this with a sample code snippet, because am not a db guy and trying my level best to solve this problem.

It would be a great favor if you could help me out on this.

Thanks,
kamal

Last edited by kamal_001; 04-12-08 at 07:57.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On