我无法执行以下过程并遇到错误:
1064 Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'aid=ass333' at line 1
CREATE DEFINER=`root`@`localhost` PROCEDURE `ref_table`()
BEGIN
declare t_name varchar(20);
declare aid1 varchar(20);
declare get_email varchar(20);
set @aid1 := 'ass333';
set @t_name := (select table_name from aid_ref where aid=@aid1);
set @get_email= CONCAT("SELECT email FROM ",@t_Name,"where aid=",@aid1);
Prepare stmt FROM @get_email;
Execute stmt;
End
如果我执行相同的过程而不使用 (,"where help=",@aid1);在 concat 函数中,我获取函数中所有电子邮件的列表,但是我需要从此过程中获取特定的电子邮件 ID
set @get_email= CONCAT("SELECT email FROM ",@t_Name,"where aid=",@aid1);
最佳答案
问题可能出在这一行:
set @get_email = CONCAT("SELECT email FROM ", @t_Name, "where @aid=", @aid1);
有人怀疑您缺少空格:
set @get_email = CONCAT("SELECT email FROM ", @t_Name, " where @aid=", @aid1);
--------------------------------------------------------^
如果值是通过用户输入提供的,那么您应该使用参数化查询。
编辑:
据推测,您的问题是值周围缺少单引号:
set @get_email = CONCAT("SELECT email FROM ", @t_Name, " where @aid = '", @aid1, "'");
请注意,如果要将参数值传递到查询字符串中,则应该使用参数化查询。
关于mysql - 错误 1064 : combining multiple strings in Concat() function:MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37482404/