Willyanto Halim
Willyanto Halim

Reputation: 413

concatenation in stored procedure mysql

I want to create concatenation for store procedure mysql.
in php I can use (.) for concatinating the variable
example :

$table = "table_".$_GET["number"];
$sql = mysqli_query($conn,select * from `".$table."` where `field`='$field');

in stored procedure mysql, I don't know how to concatinate the variable.

this is my stored procedure script.

CREATE DEFINER=`user`@`localhost` PROCEDURE `testprocedure`(v_number int(5))
BEGIN
  declare v_table varchar(20);
  set v_table = 'table_'.v_number;
  update `v_table` set `field`=v_number where `field2`='test';
END $$
DELIMITER ;

so how can I add v_number to set v_table then add v_table to update table query?

Upvotes: 1

Views: 12958

Answers (1)

MrFreezer
MrFreezer

Reputation: 1823

Use CONCAT : set v_table = CONCAT('table_',v_number);

Upvotes: 5

Related Questions