为什么在游标前面不能有其它的select
xielk 2009-11-05 11:20:35 存储过程如下:
BEGIN
declare $audit_key int default 0;
declare $kind char(2) ;
declare $netbar_key char(18);
declare $ip char(15);
declare $loadcount int default 0;
declare $insertcount int default 0;
declare $updatecount int default 0;
declare $now_time int default 0;
declare $pb_key char(18);
declare $xs_key char(18);
/*SET $now_time=UNIX_TIMESTAMP(now());
SELECT count(*) into $loadcount FROM org_logs;
INSERT audit(created,modify,status,loadcount) values($now_time,$now_time,0,$loadcount);
这几话加上注释就OK。
*/
DECLARE all_ip_cur CURSOR FOR SELECT id,ip,kind From org_logs;
OPEN all_ip_cur;
FETCH all_ip_cur into $netbar_key,$ip,$kind;
WHILE ($ip is not null) DO
IF ($kind='p')
$pb_key=$netbar_key;
ELSE IF ($kind='x')
$xs_key=$netbar_key;
END IF;
call update_ip($audit_key,$ip,$pb_key,$xs_key,@result);
IF (@result=1)
SET $insertcount=$insertcount+1;
IF (@result=2)
SET $updatecount=$updatecount+1;
FETCH all_ip_cur into $netbar_key,$ip,$kind;
END WHILE;
CLOSE all_ip_cur;
SET $now_time=UNIX_TIMESTAMP(now());
IF ($updatecount>0)
UPDATE audit SET updatecount=$updatecount,insertcount=$insertcount,loadcount=$loadcount,status=1,modify=$now_time where id=$audit_key;
END IF;
END
为什么在游标前面不能有select等话句。