Mysql-动态执行SQL语句
分类:
IT文章
•
2023-12-22 17:25:55
prepare 准备
using 使用
deallocate 释放
execute 执行
单词
delimiter $
drop procedure if exists proc $
create procedure proc()
begin
declare p1 int;
set p1 = 11;
set @p1 = p1;
prepare prod from 'select * from log where nid > ?';
execute prod using @p1;
deallocate prepare prod;
end $
delimiter ;
call proc();
代码
delimiter $
drop procedure if exists proc $
create procedure proc(in strsql varchar(128),in p1 int)
begin
set @strsql = strsql;
set @p1 = p1;
prepare prod from @strsql;
execute prod using @p1;
deallocate prepare prod;
end $
delimiter ;
call proc('select * from log where nid > ?',103);