问题
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