CREATE PROCEDURE p1() BEGIN DECLARE done INT DEFAULT FALSE; DECLARE x, y INT; DECLARE cur1 CURSOR FOR SELECT i FROM test.c1; DECLARE cur2 CURSOR FOR SELECT i FROM test.c2; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN cur1; OPEN cur2; read_loop: LOOP FETCH cur1 INTO x; FETCH cur2 INTO y; IF done THEN LEAVE read_loop; END IF; IF x < y THEN INSERT INTO test.c3 VALUES (x); ELSE INSERT INTO test.c3 VALUES (y); END IF; END LOOP; CLOSE cur1; CLOSE cur2; END; // -- Maria 10.3 CREATE PROCEDURE p1(min INT,max INT) BEGIN DECLARE done INT DEFAULT FALSE; DECLARE va INT; DECLARE cur CURSOR(pmin INT, pmax INT) FOR SELECT a FROM t1 WHERE a BETWEEN pmin AND pmax; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=TRUE; OPEN cur(min,max); read_loop: LOOP FETCH cur INTO va; IF done THEN LEAVE read_loop; END IF; INSERT INTO t1 VALUES (va,'new'); END LOOP; CLOSE cur; END; //
SQL Справочник v0.05 © 2007-2025 Igor Salnikov aka SunDoctor