Answer a question

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 ;

Answers

You are missing a comma after tablName:

 set @cmd = concat('Create table', tablName, ' as ( select name from   samprojects.projects  where type=''',projName, ''')');
Logo

华为、百度、京东云现已入驻,来创建你的专属开发者社区吧!

更多推荐