mysql 5.0.45, linux下
我在存储过程里定义如下
declare a int;
a=4;
declare gbmes_csr  CURSOR FOR SELECT id from Entity where id=a;-----这里报错
 
因为是复制环境,多台机器 如果用临时表做估计数据会导致不同步。  疑问 :
1 是否mysql 5.0.45游标不支持  where id=a  ,   也就是说,游标的where后带变量他不允许?
2 如果不支持 ,有没有其他方法做这个选择?  (复制环境,临时表容易导致数据不一致)网纱找到一个
declare _PId int DEFAULT 0;
DECLARE cur1 CURSOR FOR SELECT a1 from t1 where mediumId=CmId;
declare CONTINUE HANDLER for SQLSTATE '02000' set _done=1;  
OPEN cur1;
REPEAT    
    fetch Cur1 into _PId;
    if not _done then
           搞你的东西    end if
until _done end REPEAT; 
但是 验证是错误的

解决方案 »

  1.   

    declare a int;
    a=4;                   -- 显然语法不对,另外set a=4 必须放在dcalsre curor 之后!
    declare gbmes_csr  CURSOR FOR SELECT id from Entity where id=a;-
      

  2.   

    declare gbmes_csr CURSOR FOR SELECT id from Entity where id=a;-那么请理解这个 a 是 传入 的 存储过程的参数
      

  3.   

    这样写是ok的 
    CREATE PROCEDURE `test22222`(oldUserId int,oldId int)
    BEGIN
    declare no_more_gbmes int;
    declare aid int;
    declare gbmes_csr  CURSOR FOR SELECT id from a where userId=oldUserId and fdBoed=oldId;
    declare continue handler FOR NOT FOUND SET no_more_gbmes=1;
            SET no_more_gbmes=0;
    在mysql教程中不能批量删除存储过程或函数,只能一次删除一个存储过程或函数,删除存储过程或者函数需要有该过程或者函数的alter routine权限,mysql存储过程具体语法如下:drop { procedure | function } [ if exists] sp_name例如:使用DRop语法删除 sp_111cn.net过程;mysql>drop producdure sp_111cn.net;query OK,0 rows affected (0.00 sec)上面是删除存储过程,删除过程方法也一样  drop PROCEDURE testc();感谢楼上确实发现 mysql这个很严格。 必须 set a=4;
    另外他传入变量只能通过参数。不能在
    set a=4; -- 显然语法不对,另外set a=4 必须放在dcalsre curor 之后!
    declare gbmes_csr CURSOR FOR SELECT id from Entity where id=a
    这样写是错误的 。 他的定义不允许这样。 declare必须在最前面。  所以如果要做 只能把 这个存储过程外放到另外一个存储过程 之后在当地存储过程里 call  存储过程名称(参数1 ,参数2.)
    drop 方法名称drop sp_fanun
      

  4.   

    我的感觉是
    如果游标中加where条件并引用的是变量的值,可以放入存储过程参数中。具体的写法不太明了。等高人来指点。
      

  5.   

    declare a int default 4;-----定义的时候就给默认值
    declare gbmes_csr CURSOR FOR SELECT id from Entity where id=a;
      

  6.   

    支持 的,在声明时赋值即可
    declare a int default 4;
    declare gbmes_csr CURSOR FOR SELECT id from Entity where id=a