CREATE PROCEDURE NVL(a CHAR(32), b CHAR(32) DEFAULT NULL,
c CHAR(32) DEFAULT NULL,
d CHAR(32) DEFAULT NULL,
e CHAR(32) DEFAULT NULL,
f CHAR(32) DEFAULT NULL,
g CHAR(32) DEFAULT NULL)
RETURNING CHAR(32);
IF a IS NOT NULL THEN RETURN a;
ELIF b IS NOT NULL THEN RETURN b;
ELIF c IS NOT NULL THEN RETURN c;
ELIF d IS NOT NULL THEN RETURN d;
ELIF e IS NOT NULL THEN RETURN e;
ELIF f IS NOT NULL THEN RETURN f;
ELSE RETURN g;
END IF;
END PROCEDURE;
Or - less generally:
-- @(#)$Id: nvl_int.spl,v 1.1 1996/08/26 18:33:11 johnl Exp $
--
-- nvl_integer: return v1 if it is not null else return v2
CREATE PROCEDURE nvl_integer(v1 INTEGER, v2 INTEGER DEFAULT 0)
RETURNING INTEGER;
DEFINE rv INTEGER;
IF v1 IS NOT NULL THEN
LET rv = v1;
ELSE
LET rv = v2;
END IF
RETURN rv;
END PROCEDURE;
The CHAR version can be used for almost any type (except strings longer than 32, as written) because SE is very good at converting between types. SE does not support explicit casting, either -- it is safe to assume that SE does not have much of SQL past SQL-89.