Bug #57401 Dynamic Select in UD Function
Submitted: 12 Oct 2010 10:43 Modified: 8 Dec 2010 8:42
Reporter: PARTHA NUNDY Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S4 (Feature request)
Version:5.1.50 OS:Microsoft Windows
Assigned to: CPU Architecture:Any
Triage: Needs Triage: D5 (Feature request)

[12 Oct 2010 10:43] PARTHA NUNDY
Description:
It will be very worthy for me if the following thing can be done inside
FUNCTION like it is working fine in Procedure:

DELIMITER ;
DROP PROCEDURE IF EXISTS EVAL;

DELIMITER $$
CREATE PROCEDURE EVAL(STR VARCHAR(255),OUT J VARCHAR(255))
BEGIN
    

    SET @C=CONCAT('SELECT ',STR,' INTO @X');
    PREPARE stmt1 FROM @C;
    EXECUTE stmt1;
    DEALLOCATE PREPARE stmt1;

SELECT @X INTO J;

END$$

DELIMITER ;

How to repeat:
Pl. try to create function with PREPARE statement.
[1 Dec 2010 14:36] Susanne Ebrecht
Why do you think it should not work?
[4 Dec 2010 14:52] PARTHA NUNDY
PREPARE & EXECUTE for Dynamic Select in UD Function is not yet allowed in MySql, but in procedures it works fine.
[8 Dec 2010 8:42] Valeriy Kravchuk
Yes, it would be nice to see this limitation removed.
[25 Feb 2013 9:44] Michel Reverbel
Of course it would be extremely useful to use a dynamic statement in a function as well.

This bug is 2.5 years old and it seems according to this page and to all release notes in 5.5 and 5.6 that nothing at all was done.

If this feature was added to the stored procedure for any reason, it seems obvious that the same reason apply for functions. And at the same time, unless a stored procedure implementation is fundamentally different from a function implementation, it seems logical to add the feature to both cases.

However from this bug's status I infer that this is all wrong:
 - implementations of function and stored procedure are completely separate matters => ???
 - and, the developpers see the advantages of using a dynamic statement in a procedure, but not in a function => ???

This is very strange.

Any explanation ?