Reinventing SUBSTR ?


This "gem" found in some source from a software vendor. What better way to rewrite the SUBSTR function, than by using ... wait for it ... the SUBSTR function! And just to make sure it doesn't run TOO fast, we will throw in a SELECT-FROM-DUAL as well

FUNCTION SUBString(inputStr IN VARCHAR2,
                   startPos IN NUMBER,
                   endPos   IN NUMBER
                  ) RETURN VARCHAR2 IS
        subStr  VARCHAR2(100);
BEGIN
        subStr := null;
        SELECT SUBSTR(inputStr,startPos,endPos) INTO subStr FROM dual;
        RETURN subStr;
END;

Magic !