call mysql function by string name Can i call a mysql stored function from another mysql stored function or stored procedure, passing a string to the first function which is the name of the second function to call. I.e choosing the the second function via a value in field.

I suspect I can't and I will have to use a case statement, but I have to ask :)

Something like this? 

CREATE FUNCTION `string_processing_chain` (function_name    VARCHAR(1000),
                                            data_to_process VARCHAR(1000))
RETURNS VARCHAR(1000)
BEGIN

RETURN ($function_name)(to_process);
END
I have never heard of something like this and I have never attempted before

Here is my best guess (using Dynamic SQL)

CREATE FUNCTION `string_processing_chain` (function_name    VARCHAR(1000),
                                        data_to_process VARCHAR(1000))
RETURNS VARCHAR(1000)
BEGIN

    DECLARE rv VARCHAR(1000);

    @sql = CONCAT('SET rv = ',function_name,'(',data_to_process,')');
    PREPARE s FROM @sql;
    EXECUTE s;
    DEALLOCATE PREPARE s;

    RETURN rv ;
END


or

CREATE FUNCTION `string_processing_chain` (function_name    VARCHAR(1000),
                                        data_to_process VARCHAR(1000))
RETURNS VARCHAR(1000)
BEGIN

    SET @rv = '';

    @sql = CONCAT('SET @rv = ',function_name,'(',data_to_process,')');
    PREPARE s FROM @sql;
    EXECUTE s;
    DEALLOCATE PREPARE s;

    RETURN @rv ;
END


Give it a Try and tell us all if it worked, please !!!



From OP I used this :

CREATE PROCEDURE `string_processing_chain`( 
    function_name   VARCHAR(1000),
    data_to_process VARCHAR(1000) )
BEGIN
    SET @sql2 = CONCAT('CALL ',function_name,'(?)');
    SELECT @sql2;
    PREPARE s FROM @sql2;
    SET @a = data_to_process;
    EXECUTE s USING @a;
    DEALLOCATE PREPARE s;
END