MYSQL
CREATE DEFINER=`mbit`@`%` PROCEDURE `tsky-ads`.`P_JOB_LOOP`(
IN PROCEDURE_NAME VARCHAR(100),
IN START_DATE VARCHAR(20),
IN END_DATE VARCHAR(20) )
BEGIN
DECLARE V_UPDATE VARCHAR(20);
START TRANSACTION;
SET V_UPDATE = START_DATE;
WHILE (V_UPDATE <= END_DATE) DO
SET @V_PROCEDURES = CONCAT('CALL ' , PROCEDURE_NAME , '(' , V_UPDATE, ')');
PREPARE I_PARAMETER_DAY_STMT FROM @V_PROCEDURES;
EXECUTE I_PARAMETER_DAY_STMT;
COMMIT;
SET V_UPDATE =DATE_FORMAT(DATE_ADD(DATE_FORMAT(V_UPDATE,'%Y-%m-%d'), INTERVAL 1 DAY),'%Y%m%d');
END WHILE;
END
DB2
CREATE OR REPLACE PROCEDURE GBSC00.T_JOB_LOOP(
IN PROCEDURE_NAME VARCHAR(100),
IN START_DATE VARCHAR(20),
IN END_DATE VARCHAR(20) )
SPECIFIC T_JOB_LOOP
LANGUAGE SQL
NOT
DETERMINISTIC EXTERNAL ACTION
MODIFIES SQL DATA CALLED ON
NULL INPUT
INHERIT SPECIAL REGISTERS
OLD SAVEPOINT LEVEL
BEGIN
DECLARE V_UPDATE VARCHAR(20);
DECLARE V_PROCEDURES VARCHAR(500);
SET V_UPDATE = START_DATE;
WHILE (V_UPDATE <= END_DATE) DO SET V_PROCEDURES = '
CALL ' || PROCEDURE_NAME || ' (' || V_UPDATE || ') ';
EXECUTE IMMEDIATE V_PROCEDURES;
COMMIT;
SET V_UPDATE = TO_CHAR(TO_DATE( V_UPDATE, 'yyyymmdd')+ 1, 'yyyymmdd');
END WHILE;
END