猿问

mysql中游标为空怎么判断啊

菠萝1230
浏览 2405回答 1
1回答

慕田峪3555374

delimiter $drop procedure if exists curdemo $ CREATE PROCEDURE curdemo(pid int)  BEGIN  DECLARE notfound INT DEFAULT 0;  #定义一个辅助变量用于判断  DECLARE a int;                   #定义游标输出值赋予的变量  DECLARE cur1 CURSOR FOR SELECT id FROM test.t where id= pid;  #定义游标  DECLARE CONTINUE HANDLER FOR NOT FOUND SET notfound = 1;      #定义declare continue handler,这个会根据上下文是否有结果判断是否执行SET notfound = 1  OPEN cur1;  FETCH cur1 INTO a;  if notfound = 1 then    select 'no result';    #写业务逻辑  ELSE    select concat('result:', a);    #写业务逻辑  end if;  CLOSE cur1;END$delimiter ;call curdemo(240);
随时随地看视频慕课网APP

相关分类

MySQL
我要回答