存储过程中有个查询需要用 in 来查询,里面字符已参数传递进来
CREATE PROCEDURE `myTest`(str1 varchar(200))
BEGIN
select str1;
select * from table where str1 in (str1);
END;1:call myTest('abc'); ok ,没问题,当我吧参数拼装到多个之后,就不行了,例如('abc,def')或者("'abc','def'");如下
2:call myTest("'abc','def'");call myTest('abc,def');都不行,我直接select * from table where str1 in ('abc','def'); 这样是可以的有人知道,是咋回事吗,这个问题我今天弄了一下午了,始终没能解决掉,希望大家能指点我下,谢过了!
CREATE PROCEDURE `myTest`(str1 varchar(200))
BEGIN
select str1;
select * from table where str1 in (str1);
END;1:call myTest('abc'); ok ,没问题,当我吧参数拼装到多个之后,就不行了,例如('abc,def')或者("'abc','def'");如下
2:call myTest("'abc','def'");call myTest('abc,def');都不行,我直接select * from table where str1 in ('abc','def'); 这样是可以的有人知道,是咋回事吗,这个问题我今天弄了一下午了,始终没能解决掉,希望大家能指点我下,谢过了!
set @v_sql = concat('select * from table where str1 in (', i_param,')'); ---i_param= 'abc','def'
prepare stmt from @v_sql;
execute stmt;
BEGIN
select v_str1;
select * from table where FIND_IN_SET(str1,v_str1)
END;
set @v_sql = concat('select * from tt where str1 in (', i_param,')');
prepare stmt from @v_sql;
execute stmt;2、用FIND_IN_SET OR INSTR函数
select * from table where FIND_IN_SET(str1,v_str1)
select * from table where instr(str1,v_str1)
set @sql=concat='select IFNULL(str1,'') from table'; concat'被IFNULL给截断了, 不知道有何方方法?
用两个空格 OR * 均可
用两个空格 OR * 均可