CREATE OR REPLACE FUNCTION p_str
    (
        vString  IN varchar2,
        vSymbol  IN varchar2,
        iNum     IN INTEGER
    )
RETURN varchar2 IS
       iPreSeq INTEGER;
       iCurSeq INTEGER;
       vResult varchar2(256);
BEGIN
  IF REGEXP_LIKE(vString,'[[:print:]]') AND iNum >= 1 THEN
BEGIN
            iCurSeq := INSTR(vString,vSymbol,1,iNum);
IF iNum=1 THEN
BEGIN
IF iCurSeq=0 THEN
                    vResult :=vString;
ELSE
                    vResult :=SUBSTR(vString,1,iCurSeq-1);
END IF;
  END;
            ELSE
            BEGIN
                iPreSeq := INSTR(vString,vSymbol,1,iNum -1);
IF iPreSeq<>0 AND iCurSeq<>0 THEN
                    vResult :=SUBSTR(vString,iPreSeq+1,iCurSeq-iPreSeq-1);
ELSIF iPreSeq<>0 AND iCurSeq=0 AND LENGTH(vString)>iPreSeq THEN
                    vResult :=SUBSTR(vString,iPreSeq+1,LENGTH(vString)-iPreSeq);
     END IF;
            END;
            END IF;
        END;
        END IF;
        IF REGEXP_LIKE(vResult,'[[:print:]]') THEN
            vResult := REGEXP_SUBSTR(vResult,'[[:print:]]+');
ELSE
            vResult := '';
END IF;
RETURN(vResult);
END p_str;

posted on 2010-09-29 20:56  青衣小帽  阅读(461)  评论(0编辑  收藏  举报