
BEGIN
  IF code IS NULL THEN
    RAISE 'null value for sql code not allowed' USING ERRCODE='invalid_parameter_value';
  END IF;
/*
 * Oracle limits the range of error codes like to -20999 to -20000, but for
 * historical reasons we accept a wider range. We accept all 5 digits positive
 * and negative integers.
 */
  IF code NOT BETWEEN -20999 AND -20000 THEN
    RAISE 'error code is out of range' USING DETAIL = 'Valid range is -20999 to -20000', ERRCODE='invalid_parameter_value';
  END IF;
  RAISE 'EDB%: %', code::integer, COALESCE(msg, '<NULL>') USING ERRCODE = 'raise_exception', SQLCODE = code::integer;
END