写了个过程,但是指针curSid执行一次就停了,不知道为什么
如下图,这个sql查出的数据是不止一条的
如下图,这个sql查出的数据是不止一条的
BEGIN #Routine body goes here... DECLARE m BIGINT DEFAULT 0; DECLARE a VARCHAR(20); DECLARE o VARCHAR(10); DECLARE r VARCHAR(255); DECLARE c VARCHAR(30); DECLARE cc VARCHAR(30); DECLARE done BIGINT; DECLARE curSid CURSOR FOR SELECT app,channel,SUM(revenue) FROM YJ GROUP BY channel; #DECLARE curSid CURSOR FOR SELECT id from area; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; SET done = 0; OPEN curSid; REPEAT FETCH curSid INTO a,c,r; IF done <> 1 THEN #Key statement SET cc = SUBSTRING_INDEX(c,"YJ_451_",-1); SELECT merchant_id INTO m FROM amg.cp_sky_charge WHERE channel_child = cc LIMIT 1; INSERT INTO amg.cp_sky_charge_copy VALUES(null, NOW(), m, a, cc, "移动", r, "", ""); END IF; UNTIL done = 1 END REPEAT; CLOSE curSid; #SELECT c; #SELECT a; #SELECT * from cp_sky_charge WHERE DATE(date)=curdate; END
解决方案
10
BEGIN
#Routine body goes here…
DECLARE m BIGINT DEFAULT 0;
DECLARE a VARCHAR(20);
DECLARE o VARCHAR(10);
DECLARE r VARCHAR(255);
DECLARE c VARCHAR(30);
DECLARE cc VARCHAR(30);
DECLARE done BIGINT;
DECLARE done_o BIGINT;
#Routine body goes here…
DECLARE m BIGINT DEFAULT 0;
DECLARE a VARCHAR(20);
DECLARE o VARCHAR(10);
DECLARE r VARCHAR(255);
DECLARE c VARCHAR(30);
DECLARE cc VARCHAR(30);
DECLARE done BIGINT;
DECLARE done_o BIGINT;
DECLARE curSid CURSOR FOR SELECT app,channel,SUM(revenue) FROM YJ GROUP BY channel;
#DECLARE curSid CURSOR FOR SELECT id from area;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
SET done = 0;
OPEN curSid;
REPEAT
FETCH curSid INTO a,c,r;
IF done <> 1 THEN #Key statement
SET cc = SUBSTRING_INDEX(c,”YJ_451_”,-1);
SET done_o = done;
SELECT merchant_id INTO m FROM amg.cp_sky_charge WHERE channel_child = cc LIMIT 1;
INSERT INTO amg.cp_sky_charge_copy VALUES(null, NOW(), m, a, cc, “移动”, r, “”, “”);
SET done = done_o;
END IF;
UNTIL done = 1 END REPEAT;
CLOSE curSid;
#SELECT c;
#SELECT a;
#SELECT * from cp_sky_charge WHERE DATE(date)=curdate;
END
30
对的,就是在意思