pears.dialable

Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.

Original SQL

CREATE FUNCTION "pears"."dialable"( 
  /* Application Maintained Function / Procedure - DO NOT EDIT*/
  IN "s" CHAR(100) ) 
RETURNS CHAR(100)
BEGIN
  DECLARE "rv" CHAR(100);
  DECLARE "c" CHAR(1);
  DECLARE "i" SMALLINT;
  SET "rv" = '';
  SET "i" = 1;
  while "i" <= "length"("s") loop
    SET "c" = "substr"("s","i",1);
    IF "c" LIKE '[0123456789]' THEN
      SET "rv" = "rv"+"c"
    ELSE IF "c" = '(' THEN
        IF "substr"("s","i"+2,1) = ')' THEN
          SET "i" = "i"+2
        END IF
      END IF
    END IF;
    SET "i" = "i"+1
  END loop;
  IF "length"("rv") > 6 AND "substr"("rv",1,1) <> '0' THEN
    SET "rv" = '+'+"rv"
  END IF;
  RETURN("rv")
END