Skip to content

Instantly share code, notes, and snippets.

@gmgent
Created March 8, 2011 19:41
Show Gist options
  • Select an option

  • Save gmgent/860870 to your computer and use it in GitHub Desktop.

Select an option

Save gmgent/860870 to your computer and use it in GitHub Desktop.
CREATE PROCEDURE testy ()
BEGIN
declare a, b int;
DECLARE done int DEFAULT 0;
DECLARE masterCursor CURSOR
FOR
SELECT SUM(sales.amount) amt, sales.item_month
FROM sales
WHERE RETAILER_ID = 336
GROUP BY sales.item_month;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN masterCursor;
REPEAT
FETCH masterCursor INTO a, b;
IF NOT done THEN
insert into revplan (amount, item_month)
values (a,b);
END IF;
UNTIL done END REPEAT;
CLOSE masterCursor;
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment