Created
March 30, 2011 14:45
-
-
Save pilcrow/894531 to your computer and use it in GitHub Desktop.
Firebird util$range stored procedure
This file contains 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
-- UTIL$RANGE(start, stop, step) | |
-- | |
-- This file is in the Public Domain. | |
-- Firebird selectable stored procedure for producing integer ranges. | |
-- (Mike Pomraning; 2011-03-30) | |
-- | |
CREATE EXCEPTION util$err_range_zero_step 'step size may not be zero'; | |
SET TERM !!; | |
CREATE PROCEDURE util$range("Start" INTEGER, "Stop" INTEGER, "Step" INTEGER) | |
RETURNS (i INTEGER) AS | |
BEGIN | |
IF ("Step" > 0) THEN BEGIN | |
i = "Start"; | |
WHILE (i <= "Stop") DO BEGIN | |
SUSPEND; | |
i = i + "Step"; | |
END | |
END | |
ELSE IF ("Step" < 0) THEN BEGIN | |
i = "Start"; | |
WHILE (i >= "Stop") DO | |
BEGIN | |
SUSPEND; | |
i = i + "Step"; | |
END | |
END | |
ELSE IF ("Step" = 0) THEN | |
EXCEPTION util$err_range_zero_step; | |
-- ELSE return empty set | |
END !! | |
SET TERM ;!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment