The following function is intended to divide up a delimited CLOB into a string array:
FUNCTION SPLIT_CLOB(sText IN clob, sDel IN VARCHAR2 := ',') RETURN CLOB_ARRAY IS
nStartIdx PLS_INTEGER :=开发者_运维百科 1;
nEndIdx PLS_INTEGER := 1;
oRet CLOB_ARRAY := CLOB_ARRAY();
BEGIN
IF sText IS NULL THEN RETURN oRet; END IF;
IF DBMS_LOB.getlength(sText) = 0 THEN RETURN oRet; END IF;
LOOP
nEndIdx := DBMS_LOB.INSTR(sText, sDel, nStartIdx);
IF nEndIdx > 0 THEN
oRet.Extend;
/* compiler error on this statement: */
oRet(oRet.LAST) := DBMS_LOB.SUBSTR(sText, (nEndIdx – nStartIdx), nStartIdx);
nStartIdx := nEndIdx + LENGTH(sDel);
ELSE
oRet.Extend();
oRet(oRet.LAST) := DBMS_LOB.SUBSTR(lob_loc => sText, offset => nStartIdx);
EXIT;
END IF;
END LOOP;
RETURN oRet;
END SPLIT_CLOB;
The line:
oRet(oRet.LAST) := DBMS_LOB.SUBSTR(sText, (nEndIdx – nStartIdx), nStartIdx);
throws PLS-00103 compiler errors. But if I change the call to:
oRet(oRet.LAST) := DBMS_LOB.SUBSTR(sText, 5, nStartIdx);
everything is fine. I've tried creating another variable to do the subtraction ahead of time, but ran into the same PLS-00103 error.
Have I lose my touch? Did I forget how to subtract two numbers or something?
Please help. Thanks.
EDIT
Okay, the WEIRDEST thing just happened... in the rest of this package, I know I was subtracting some PLS_INTEGERs somewhere else in a different function.... so I found such an example, then COPY & PASTE the minus sign found in my other function, and the thing compiles...
Thanks for your help...
Why not do the calculation before the
oRet(oRet.LAST) := DBMS_LOB.SUBSTR(sText, (nEndIdx – nStartIdx), nStartIdx);
eg
calcValue := nEndIdx – nStartIdx;
oRet(oRet.LAST) := DBMS_LOB.SUBSTR(sText, calcValue, nStartIdx);
"Operations involving patterns as parameters, such as COMPARE, INSTR, and SUBSTR do not support regular expressions or special matching characters (such as % in the LIKE operator in SQL) in the pattern parameter or substrings." http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm
I think you should calculate "nEndIdx – nStartIdx" outside the SUBSTR Function
Substr Ref. http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#i999349
精彩评论