CREATE OR REPLACE FUNCTION BETWNSTR(A_STRING VARCHAR2, A_START_POS INTEGER, A_END_POS INTEGER) RETURN VARCHAR2 IS
  L_START_POS PLS_INTEGER := A_START_POS;
BEGIN
  IF L_START_POS = 0 THEN
    L_START_POS := 1;
  END IF;
  RETURN SUBSTR(A_STRING, L_START_POS, A_END_POS - L_START_POS + 1);
END;
/
