Tuesday, December 27, 2011

Get next token from a String (Oracle)


<< Previous Table of Categories Next >>


CREATE OR REPLACE FUNCTION NEXT_TOKEN(P_STR       IN OUT VARCHAR2,
                                      P_DELIMITER IN VARCHAR2)
  RETURN VARCHAR2 IS
  V_TOKEN VARCHAR2(256);
  V_POS   NUMBER(11);
BEGIN
  V_POS := INSTR(P_STR, P_DELIMITER);
  IF V_POS = 0 THEN
    V_TOKEN := P_STR;
    P_STR   := '';
  ELSE
    V_TOKEN := SUBSTR(P_STR, 1, V_POS - 1);
    P_STR   := SUBSTR(P_STR, V_POS + 1);
  END IF;
  RETURN V_TOKEN;
END NEXT_TOKEN;

No comments:

Post a Comment