下面给出的代码是存储过程(mysql 5.5.20)的一部分:
prepare stmnt1 from concat('insert into ' , tableName , '(employee_id , administrator_id) values(? , ?) ' ) ;
set @a = 19 ;
set @b = 11;
execute stmnt1 using @a , @b ;
tableName
是局部变量
当我创建程序时,我收到此错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'concat('insert into ' ,
tableName , '(employee_id , administrator_id) values(? ' at line 23
似乎这种语句在mysql中是不可能的。
请帮忙。谢谢。
答案 0 :(得分:3)
请试试这个。
set @sql = concat('insert into ' , tableName , '(employee_id , administrator_id) values(? , ?) ' ) ;
prepare stmnt1 from @sql;
set @a = 19 ;
set @b = 11;
execute stmnt1 using @a , @b ;
deallocate prepare stmnt1;
答案 1 :(得分:3)
在变量
中使用它set @sql_string =
concat('insert into ' , tableName , '(employee_id , administrator_id) values(? , ?) ' ) ;
prepare stmnt1 from @sql_string;
set @a = 19 ;
set @b = 11;
execute stmnt1 using @a , @b ;