Passing column name as a parameter in mysql stored function

后端 未结 3 1457
再見小時候
再見小時候 2021-01-14 05:11

I am using a MySQL stored function where I have created a function and I have passed column name as a parameter to this function. Suppose

CREATE DEFINER=`ro         


        
3条回答
  •  温柔的废话
    2021-01-14 05:50

    After a long search I found that a stored function can be used only to return a single value or a calculated answer (Arithmetic). For your query just use a stored procedure. It is as simple as creating a query from the front end. And here is the syntax:

    Use CONCAT(X1,X2,X3 . . .) to do it as you would like.

    CREATE DEFINER=`root`@`localhost` PROCEDURE `Test`(table longtext,column longtext,e_id longtext)
    
    SET @s=CONCAT('Select ',table,' from ', column, 'Where employee = ',e_id);
    
    PREPARE stmt1 FROM @s;
    
    EXECUTE stmt1;
    
    DEALLOCATE PREPARE stmt1;
    
    END
    

提交回复
热议问题