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

mysql存储过程能动态定义光标吗?
create procedure repairChild(in uid int, in type_get char(6))
begin
declare userCusor cursor for select uid from by_users……
if uid = 0 then
……
else
……
end if;
end
我需要根据传进来的uid生成userCusor光标,可是mysql declare语句必须放在开头,有什么办法实现吗?

------解决方案--------------------
对 只能放在开头
有什么需求必须放在后面吗
------解决方案--------------------
不可以动态定义,但可以使用变量。这个变量会跟着变化。 关闭然后再OPEN一下就行。
------解决方案--------------------
不能动态定义的,但可使用变量。
变量会随着变化的。
------解决方案--------------------
不能动态定义游标,间接方法

declare userCusor cursor for select uid from lsb
....
create table lsb as select * from by_users where id=uid
.....