android 服务器端开发中遇到这么一个问题:
突然发现将字符串传入到存储过程,参数为 ‘1‘,‘2‘ ,竟然执行无效
所以看到网上有在存储过程中直接拼凑sql的代码,今天也试了一下,可以执行了,代码如下:
CREATE DEFINER = ‘abc‘@‘%‘ PROCEDURE ConfirmAcceptorListProc(in p_task_id varchar(20),in p_user_ids text,out p_msgtype varchar(20),out p_msg varchar(20)) begin DECLARE m_user_ids varchar(1000); DECLARE t_error INTEGER DEFAULT 0; DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1; SET @SEL=‘update go_task_acceptor set status =\‘2\‘ where status = \‘1\‘ AND task_id = \‘‘; set @sentence = concat(@sel,p_task_id,‘\‘ AND acceptor_id in (‘,p_user_ids,‘);‘); -- 连接字符串生成要执行的SQL语句 prepare stmt from @sentence; -- 预编释一下。 “stmt”预编释变量的名称, START TRANSACTION; execute stmt; -- 执行SQL语句 select row_count() into p_msg; if t_error = 1 then ROLLBACK; set p_msgtype = ‘-1‘; else COMMIT; set p_msgtype = ‘1‘; end if; deallocate prepare stmt; -- 释放资源 end
以上存储过程里面拼凑出来的sql代码是:
update go_task_acceptor set status =‘2‘ where task_id = p_task_id and status = ‘1‘ and acceptor_id in (‘s‘,‘4‘);
MYSQL存储过程实现in传入参数 where in('1','2')
时间: 2024-09-30 06:54:50