额 但是我想它受影响..比如: declare tempid int; declare mycursor CURSOR for select id from table where id=tempid; 如上我的tempid这个变量是需要后面取得并且赋值的 但是如果: declare tempid int; set tempid=2; declare mycursor CURSOR for select id from table where id=tempid; 这样定义的话 会编译不过,那么我只能把游标的定义提前, 那么当我后面打开游标 我当然希望我的变量能影响游标的结果,比如: declare tempid int; declare mycursor CURSOR for select id from table where id=tempid; set tempid=2; open mycursor; 希望游标执行的话 里面的变量tempid=2,如果这样不行的话,那么应该怎么处理呢?
declare tempid int; declare mycursor CURSOR for select id from table where id=tempid; set tempid=2; open mycursor;游标应该返回id=2的数据
select tempid:=id from table where tempname='需求';
这样 编译是通不过的.
declare tempid int;
select id into tempid from table where tempname='需求';
在问个 在存储过程中 如果要使用游标 因为游标的定义不允许 别的可执行的语句在前面 那么我就会放在前面定义
但是如果我的游标中使用了变量 那么当我打开游标前 给变量赋值,当我打开游标后 这个变量会影响游标的结果么?
declare tempid int;
declare mycursor CURSOR for select id from table where id=tempid;
如上我的tempid这个变量是需要后面取得并且赋值的 但是如果:
declare tempid int;
set tempid=2;
declare mycursor CURSOR for select id from table where id=tempid;
这样定义的话 会编译不过,那么我只能把游标的定义提前,
那么当我后面打开游标 我当然希望我的变量能影响游标的结果,比如:
declare tempid int;
declare mycursor CURSOR for select id from table where id=tempid;
set tempid=2;
open mycursor;
希望游标执行的话 里面的变量tempid=2,如果这样不行的话,那么应该怎么处理呢?
declare mycursor CURSOR for select id from table where id=tempid;
set tempid=2;
open mycursor;游标应该返回id=2的数据