I am trying to create store procedure as follows
CREATE PROCEDURE `Test1` (IN projName VARCHAR(200), IN tablName VARCHAR(200))
BEGIN
set @cmd = concat('Create table', tablName ' as ( select name from samprojects.projects where type=',projName')');
PREPARE stmt FROM @cmd;
EXECUTE stmt;
END
And getting below error
ERROR 1583: Incorrect parameters in the call to native function 'concat'
Any idea how to resolve this.
I am using MYSQL workbench for running sql queries
SQL script generated by MYSQL workbench is as follows
USE `samprojects`;
DROP procedure IF EXISTS `Test1`;
DELIMITER $$
USE `samprojects`$$
CREATE PROCEDURE `Test1` (IN projName VARCHAR(200), IN tablName VARCHAR(200))
BEGIN
set @cmd = concat('Create table', tablName, ' as ( select name from samprojects.projects where type=',projName')');
PREPARE stmt FROM @cmd;
EXECUTE stmt;
END$$
DELIMITER ;
You are missing a comma after tablName
:
set @cmd = concat('Create table', tablName, ' as ( select name from samprojects.projects where type=''',projName, ''')');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With