Oracle Procedure call 字符串太长

Oracle Procedure call too long string

你好,我有一个程序像

    PROCEDURE PR_SEARCH(P_FABRIC IN VARCHAR2, P_ORG IN NUMBER,P_POS IN VARCHAR2,P_SICIL IN clob,P_EXISTS IN clob, PRC OUT SYS_REFCURSOR) IS BEGIN  
        OPEN PRC FOR
        SELECT SICIL_KOD AS SICIL,ad ||' '||soyad as NAME_SURNAME FROM
        BMS.GEN_PERSONEL GP WHERE SICIL_KOD>10000 AND GP.PERSONEL_ALT_ALAN  IN ('IZ01','IZ02','IZ03','IZ04') AND
        (P_FABRIC='-1' OR GP.PERSONEL_ALT_ALAN=P_FABRIC) 
        AND
        (P_ORG=-1 OR GP.SAP_ORG_KOD=P_ORG)
         AND
        (P_POS='-1' OR GP.POZISYON_ACIKLAMA=P_POS)
        AND
        (P_SICIL IS NULL OR GP.SICIL_KOD IN (select regexp_substr(to_char(P_SICIL),'[^,]+', 1, level) AS DEPTS from dual connect by regexp_substr(to_char(P_SICIL), '[^,]+', 1, level) is not null))
        AND 
        (P_EXISTS IS NULL OR GP.SICIL_KOD NOT IN (select regexp_substr(to_char(P_EXISTS),'[^,]+', 1, level) AS DEPTS from dual connect by regexp_substr(to_char(P_EXISTS), '[^,]+', 1, level) is not null))
        ORDER BY SICIL_KOD
        ;
    END;

我的问题是 P_SICIL 或 P_EXISTS 可能太长,因此所有长度可能超过 4000 个字符。 当我调用程序时,它给出以下错误

ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 14103, maximum: 4000)

如果我不使用 to_char 作为 clob,那么我会在下面出现错误

ORA-00932: inconsistent datatypes: expected - got CLOB ORA-06512: at "CARDREADER.PA_KART_READER", line 285 ORA-06512: at line 2

如果我不使用 clob 而使用 varchar2 作为参数类型,那么我会得到错误

ORA-01460: unimplemented or unreasonable conversion requested ORA-06512: at "CARDREADER.PA_KART_READER", line 284 ORA-06512: at line 2

如何在 oracle 中解决这个问题?

提前致谢

问题是您在使用 TO_CHAR 函数时试图将 CLOB 转换为 VARCHAR2REGEXP_SUBSTR 可以将 CLOBs 作为输入参数,所以尽量不要转换 CLOBs,而是转换 REGEXP_SUBSTR 的结果以与 SICIL_KOD 进行比较。

PROCEDURE PR_SEARCH (P_FABRIC   IN     VARCHAR2,
                     P_ORG      IN     NUMBER,
                     P_POS      IN     VARCHAR2,
                     P_SICIL    IN     CLOB,
                     P_EXISTS   IN     CLOB,
                     PRC           OUT SYS_REFCURSOR)
IS
BEGIN
    OPEN PRC FOR   SELECT SICIL_KOD AS SICIL, ad || ' ' || soyad AS NAME_SURNAME
                     FROM BMS.GEN_PERSONEL GP
                    WHERE     SICIL_KOD > 10000
                          AND GP.PERSONEL_ALT_ALAN IN ('IZ01',
                                                       'IZ02',
                                                       'IZ03',
                                                       'IZ04')
                          AND (P_FABRIC = '-1' OR GP.PERSONEL_ALT_ALAN = P_FABRIC)
                          AND (P_ORG = -1 OR GP.SAP_ORG_KOD = P_ORG)
                          AND (P_POS = '-1' OR GP.POZISYON_ACIKLAMA = P_POS)
                          AND (   P_SICIL IS NULL
                               OR GP.SICIL_KOD IN (    SELECT TO_CHAR (REGEXP_SUBSTR (P_SICIL,
                                                                                      '[^,]+',
                                                                                      1,
                                                                                      LEVEL))    AS DEPTS
                                                         FROM DUAL
                                                   CONNECT BY REGEXP_SUBSTR (P_SICIL,
                                                                             '[^,]+',
                                                                             1,
                                                                             LEVEL)
                                                                  IS NOT NULL))
                          AND (   P_EXISTS IS NULL
                               OR GP.SICIL_KOD NOT IN (    SELECT TO_CHAR (REGEXP_SUBSTR (P_EXISTS,
                                                                                          '[^,]+',
                                                                                          1,
                                                                                          LEVEL))    AS DEPTS
                                                             FROM DUAL
                                                       CONNECT BY REGEXP_SUBSTR (P_EXISTS,
                                                                                 '[^,]+',
                                                                                 1,
                                                                                 LEVEL)
                                                                      IS NOT NULL))
                 ORDER BY SICIL_KOD;
END;
END;