Skip to main content

Mysql: Multiple loop cursor in procedure

DELIMITER $$

DROP PROCEDURE IF EXISTS `updatequestion` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `updatequestion`()

 BLOCK1: begin
     declare v_col1 int;
     declare no_more_rows1 boolean default FALSE;
     declare cursor1 cursor for
         select col1
         from   MyTable;
     declare continue handler for not found
         set no_more_rows1 := TRUE;


     open cursor1;
     LOOP1: loop
         fetch cursor1
         into  v_col1;
         if no_more_rows1 then
             close cursor1;
             leave LOOP1;
         end if;


         BLOCK2: begin
             declare v_col2 int;
             declare no_more_rows2 boolean default FALSE;
             declare cursor2 cursor for
                 select col2
                 from   MyOtherTable
                 where  ref_id = v_col1;
             declare continue handler for not found
                 set no_more_rows2 := TRUE;
             open cursor2;
             LOOP2: loop
                 fetch cursor2
                 into  v_col2;
                 if no_more_rows then
                     close cursor2;
                     leave LOOP2;
                 end if;
             end loop LOOP2;
         end BLOCK2;

     end loop LOOP1;

end BLOCK1$$


DELIMITER ;

Comments

Popular posts from this blog

Reading Large JSON file through PHP Script

 <?php /* cat mexico.geojson | wc sed ':a;N;$!ba;s/\n/ /g' mexico.geojson  > mexico.geojson_out1 cat mexico.geojson_out1 | wc http://localhost/Utility/cord/largefile.php?filename=mexico.geojson_out1 sed -E 's/\{ "type": "FeatureCollection", "name": "mexico_administrative_osm_province_boundaries", "crs": \{ "type": "name", "properties": \{ "name": "urn:ogc:def:crs:OGC:1.3:CRS84" \} \}, "features": \[//g' ./mexico.geojson_out1  > mexico.geojson_out2 http://localhost/Utility/cord/largefile.php?filename=mexico.geojson_out2 sed -E 's/(\[|\{|\}|\])/ \1 /g' ./mexico.geojson_out2 > ./output/mexico.geojson_output http://localhost/Utility/cord/largefile.php?filename=output/mexico.geojson_output */ ini_set('max_execution_time', '500'); //300 seconds = 5 minutes ini_set('memory_limit', '1G');   //ini_set('max_execution...

Splitting Comma-Separated Values In MySQL

CREATE TABLE numbers (n INT);  INSERT INTO numbers VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9),     select id, substring_index( substring_index(email_recipients, ',', n), ',', -1 ) as email from dashboards join numbers on char_length(email_recipients) - char_length(replace(email_recipients, ',', '')) >= n - 1     Reference Site : https://www.sisense.com/blog/splitting-comma-separated-values-in-mysql/