Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save roborobs/4713572 to your computer and use it in GitHub Desktop.

Select an option

Save roborobs/4713572 to your computer and use it in GitHub Desktop.
mysql: loop (stops when condition has reached)
DELIMITER $$
CREATE PROCEDURE pages(in _cID int)
BEGIN
declare cID_new int;
declare cvName_new varchar(255);
set cID_new = _cID;
simple_loop: LOOP
select distinct pages.cParentID, collectionversions.cvName
from pages, collectionversions
where pages.cID = cID_new AND collectionversions.cID = pages.cID;
IF cID_new = 1 THEN
LEAVE simple_loop;
END IF;
select distinct pages.cParentID, collectionversions.cvName
into cID_new, cvName_new
from pages, collectionversions
where pages.cID = cID_new AND collectionversions.cID = pages.cID;
END LOOP simple_loop;
END $$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment