Skip to content

Instantly share code, notes, and snippets.

@pilcrow
Created March 30, 2011 14:45
Show Gist options
  • Save pilcrow/894531 to your computer and use it in GitHub Desktop.
Save pilcrow/894531 to your computer and use it in GitHub Desktop.
Firebird util$range stored procedure
-- 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