Call to stored procedure , when procedure name in a variable in mysql

左心房为你撑大大i 提交于 2019-12-01 12:57:48

问题


I have mysql stored procedure and i want to call to that and procedure name in a variable i used prepared statements but it gave me an error ,

im not a expert in mysql.

here is the prepared statement

   > PREPARE stmt1 FROM 'CALL ? (?,?,?)'; 
     SET @q = 'sys_search'; 
     SET @a ='All_Employees';
     SET @b = 1; 
     SET @c = 1; 
     EXECUTE stmt1 USING @q,@a,@b,@c;

can any one give me the solution?


回答1:


@Rahul , @Tim Biegeleisen Thank you for your responses. I used this statements to work done.

SET @q = 'sys_search';
SET @q2 = CONCAT('CALL ',@q,'(?,?,?)');
PREPARE stmt1 FROM @q2;
SET @a = 'All_Employees';
SET @b = 1;
SET @c = 1;
EXECUTE stmt1 USING @a, @b,@c; 



回答2:


I don't think you can execute a stored procedure using dynamic query. Rather create the dynamic query with the SELECT involved in your procedure and execute that.



来源:https://stackoverflow.com/questions/37641432/call-to-stored-procedure-when-procedure-name-in-a-variable-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!