日期:2014-05-16  浏览次数:20811 次

存储过程中用预处理
delimiter   $$
drop   procedure   if   exists   procPrepare$$
create   procedure   procPrepare(in   field1   int,in   field2   int,in   field3   int)
begin
        prepare   stmt   from   "insert   into   tbl_temp(field_a,field_b,field_c)   values(?,?,?) ";
        execute   stmt   using   field1,field2,field3;
end$$
delimiter   ;

这样有什么错误?为什么编译不了.

------解决方案--------------------
using 后面必须是静态的值,不能是动态变量。

delimiter $$
drop procedure if exists procPrepare$$
create procedure procPrepare(in field1 int,in field2 int,in field3 int)
begin
set @str = concat( 'insert into tbl_temp(field_a,field_b,field_c) values( ',field1, ', ',field2, ', ',field3, ') ');
prepare stmt from @str;
execute stmt;
deallocate prepare stmt;
end$$
delimiter ;


(0 row(s)affected)
(0 ms taken)

(0 row(s)affected)
(0 ms taken)