Oracle存储过程OUT CLOB返回错误字符串缓冲区太小
Posted
技术标签:
【中文标题】Oracle存储过程OUT CLOB返回错误字符串缓冲区太小【英文标题】:Oracle Stored Procedure OUT CLOB return error character string buffer too small 【发布时间】:2018-12-04 16:43:47 【问题描述】:我有一个从应用程序调用的 Oracle 存储过程。存储过程将搜索我的应用程序提供的参数并查询出数据,然后将信息消息返回给我的应用程序。
但是,我得到一个错误
ORA-06502:PL/SQL:数字或值错误:字符串缓冲区太小
在第 37 行,即 P_INFO,我这里使用的是 CLOB 数据类型,假设它可以支持非常大量的字符,假设数据返回超过 100k 个字符。
create or replace PROCEDURE SimpleProcedure
(
P_ID VARCHAR2,
P_INFO OUT CLOB
) AS
V_PROJ_ID VARCHAR2(50);
V_PROJ_NAME NVARCHAR2(1000);
V_APP_ID VARCHAR2(50);
V_APP_STATUS VARCHAR2(50);
CURSOR SUB_ATTACH_CURSOR(APP_ID VARCHAR2) IS
SELECT S.SUBMISSION_ID,
SA.FILE_ID,
SA.STATUS_CODE,
E.FILENAME_TEXT
FROM SUBM_ATTCHMNT SA
INNER JOIN SUB_SUBMISSION S
ON S.SUBMISSION_ID = SA.SUBMISSION_ID
INNER JOIN SUB_FILE E
ON E.FILE_ID = SA.FILE_ID
WHERE S.APP_ID = APP_ID;
BEGIN
SELECT P.PROJECT_ID,
P.NAME_TEXT,
A.APP_ID,
A.STATUS_CODE
INTO V_PROJ_ID, V_PROJ_NAME, V_APP_ID, V_APP_STATUS
FROM SUB_APP A
INNER JOIN SUB_PROJ P
ON P.PROJECT_ID = A.PROJECT_ID
WHERE A.ID = P_ID;
P_INFO := 'Information:
Proj id: ' || V_PROJ_ID || ',
Proj name: ' || V_PROJ_NAME || ',
App id: ' || V_APP_ID || ',
App status: ' || V_APP_STATUS || ',';
FOR SA IN SUB_ATTACH_CURSOR(V_APP_ID) LOOP
P_INFO := P_INFO || 'Submission id: ' || SA.SUBMISSION_ID ||
',file id: ' || SA.FILE_ID || ', file name: ' ||
SA.FILENAME_TEXT || ', file Status: ' ||
SA.STATUS_CODE || ' ';
END LOOP;
END SimpleProcedure;
【问题讨论】:
【参考方案1】:像这样尝试(使用DBMS_LOB.APPEND):
create or replace PROCEDURE SimpleProcedure(P_ID VARCHAR2, P_INFO OUT CLOB) AS
V_PROJ_ID VARCHAR2(50);
V_PROJ_NAME NVARCHAR2(1000);
V_APP_ID VARCHAR2(50);
V_APP_STATUS VARCHAR2(50);
v_SA VARCHAR2(30000);
CURSOR SUB_ATTACH_CURSOR(APP_ID VARCHAR2) IS
SELECT S.SUBMISSION_ID,
SA.FILE_ID,
SA.STATUS_CODE,
E.FILENAME_TEXT
...
BEGIN
SELECT P.PROJECT_ID,
P.NAME_TEXT,
A.APP_ID,
A.STATUS_CODE
...
P_INFO := 'Information:
Proj id: ' || V_PROJ_ID || ',
Proj name: ' || V_PROJ_NAME || ',
App id: ' || V_APP_ID || ',
App status: ' || V_APP_STATUS || ',';
FOR SA IN SUB_ATTACH_CURSOR(V_APP_ID) LOOP
v_SA := 'Submission id: ' || SA.SUBMISSION_ID ||
',file id: ' || SA.FILE_ID || ', file name: ' ||
SA.FILENAME_TEXT || ', file Status: ' ||
SA.STATUS_CODE || ' ';
DBMS_LOB.APPEND(P_INFO, v_SA);
END LOOP;
END SimpleProcedure;
【讨论】:
以上是关于Oracle存储过程OUT CLOB返回错误字符串缓冲区太小的主要内容,如果未能解决你的问题,请参考以下文章
Oracle 存储过程因复杂类型的 clob 而失败,并带有 ORA-22922