似乎无法在 PLSQL 函数中减去两个数字

发布于 2024-11-08 05:10:41 字数 1488 浏览 0 评论 0原文

以下函数旨在将分隔的 CLOB 划分为字符串数组:

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;

该行:

oRet(oRet.LAST) := DBMS_LOB.SUBSTR(sText, (nEndIdx – nStartIdx), nStartIdx);

抛出 PLS-00103 编译器错误。但如果我将调用更改为:

oRet(oRet.LAST) := DBMS_LOB.SUBSTR(sText, 5, nStartIdx);

一切都很好。我尝试创建另一个变量来提前进行减法,但遇到了相同的 PLS-00103 错误。

我失去了联系吗?我是否忘记了如何减去两个数字或其他什么?

请帮忙。谢谢。

编辑

好吧,最奇怪的事情刚刚发生了......在这个包的其余部分,我知道我在不同的函数中的其他地方减去了一些 PLS_INTEGER......所以我找到了这样一个例子,然后复制&粘贴在我的其他函数中找到的减号,然后编译...

感谢您的帮助...

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

大姐,你呐 2024-11-15 05:10:41

之前进行计算

oRet(oRet.LAST) := DBMS_LOB.SUBSTR(sText, (nEndIdx – nStartIdx), nStartIdx); 

为什么不在eg

calcValue := nEndIdx – nStartIdx;

oRet(oRet.LAST) := DBMS_LOB.SUBSTR(sText, calcValue, nStartIdx); 

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); 
暖树树初阳… 2024-11-15 05:10:41

“涉及模式作为参数的操作(例如 COMPARE、INSTR 和 SUBSTR)不支持模式参数或子字符串中的正则表达式或特殊匹配字符(例如 SQL 中 LIKE 运算符中的 %)。” http://download.oracle.com/docs/cd /B19306_01/appdev.102/b14258/d_lob.htm

我认为您应该在 SUBSTR 函数

Substr Ref 之外计算“nEndIdx – nStartIdx”。 http://download.oracle.com/docs /cd/B19306_01/appdev.102/b14258/d_lob.htm#i999349

"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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文