RSS

Looping data di Myql



CREATE PROCEDURE `DoRasioHarianRange`(IN TglAwal DATE, IN TglAkhir DATE)
    NOT DETERMINISTIC
    SQL SECURITY DEFINER
    COMMENT ''
BEGIN
   DECLARE xTanggal DATE;
   -- this flag will be set to true when cursor reaches end of table

   DECLARE exit_loop BOOLEAN;
   -- Declare the cursor

   DECLARE rasio_cursor CURSOR FOR
     SELECT jurnal_tanggal FROM temp_tanggal
            WHERE jurnal_tanggal BETWEEN TglAwal AND TglAkhir;

   -- set exit_loop flag to true if there are no more rows
   DECLARE CONTINUE HANDLER FOR NOT FOUND SET exit_loop = TRUE;

   -- open the cursor
   OPEN rasio_cursor;

   -- start looping
   rasio_loop: LOOP

     -- read the name from next row into the variables
     FETCH  rasio_cursor INTO xTanggal;
     CALL DoRasioHarian(xTanggal);

     -- check if the exit_loop flag has been set by mysql,
     -- close the cursor and exit the loop if it has.
     IF exit_loop THEN
         CLOSE rasio_cursor;
         LEAVE rasio_loop;
     END IF;

   END LOOP rasio_loop;
 END;

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comments:

Posting Komentar