mysql中如何获取没有输入参数的存储过程的返回值
1个回答
2014-11-14
展开全部
p_cloumns varchar(500),p_tables varchar(100),p_where varchar(4000),p_order varchar(100),p_pageindex int,p_pagesize int,out p_recordcount int,out p_pagecount int
$:begin
declare v_sqlcounts varchar(4000);
declare v_sqlselect varchar(4000);
#拼接查询总记录的SQL语句
set v_sqlcounts = concat('select count(*) into @recordcount from ',p_tables,p_where);
#select v_sqlcounts;leave $;
set @sqlcounts = v_sqlcounts;
prepare stmt from @sqlcounts;
execute stmt;
deallocate prepare stmt;
#获取动态SQL语句返回值
set p_recordcount = @recordcount;
#根据总记录跳数计算出总页数
set p_pagecount = ceiling((p_recordcount+0.0)/p_pagesize);
if p_pageindex <1 then
set p_pageindex = 1;
elseif p_pageindex > p_pagecount and p_pagecount <> 0 then
set p_pageindex = p_pagecount;
end if;
#拼接分页查询记录的动态SQL语句
set v_sqlselect = concat('select ',p_cloumns,' from ',p_tables,p_where,if(p_order is not null,p_order,''),' limit ',(p_pageindex-1)*p_pagesize,' , ',p_pagesize);
#select v_sqlselect;leave $;
set @sqlselect = v_sqlselect;
prepare stmtselect from @sqlselect;
execute stmtselect;
deallocate prepare stmtselect;
end $
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询