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 > MySQL > Can a function return a temporary table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-29-11, 07:31
Nagashree Nagashree is offline
Registered User
 
Join Date: Mar 2011
Posts: 3
Question Can a function return a temporary table

Can a MYSQL function return a temporary table that was created inside the same function ?

Like this :

DELIMITER $$
CREATE FUNCTION `getPolicy`(CID SMALLINT, TID SMALLINT)returns
tt_Rtab TABLE (a INT, i BIT, value VARCHAR(8000))

BEGIN
declare V varchar(30);

CREATE TEMPORARY TABLE IF NOT EXISTS tt_RetTab
(
attribute INT,
inherit BIT,
`value` VARCHAR(8000)
);
DROP TEMPORARY TABLE IF EXISTS tt_Parents;



END $$

DELIMITER ;

-----------------------------------------------

This can be done in SQL Server DB.
How to do the same in MYSQL?
Reply With Quote
  #2 (permalink)  
Old 03-29-11, 10:32
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
Yes it is possible. Try using the PREPARE FROM, EXECUTE and DEALLOCATE PREPARE statements as follows:

Code:
delimiter $$
create procedure sptest()
begin
prepare stmt from "CREATE TEMPORARY TABLE IF NOT EXISTS tt_RetTab(attribute int, inherit bit, value varchar(8000))";
execute stmt;
deallocate prepare stmt;
end;
$$
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
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