Roshan
Roshan

Reputation: 3346

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

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?

Upvotes: 1

Views: 1331

Answers (2)

Roshan
Roshan

Reputation: 3346

@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; 

Upvotes: 3

Rahul
Rahul

Reputation: 77926

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.

Upvotes: 0

Related Questions