Created
February 5, 2013 10:26
-
-
Save roborobs/4713572 to your computer and use it in GitHub Desktop.
mysql: loop (stops when condition has reached)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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