将 varchars 合并为一个 CLOB
Merging varchars into one CLOB
我有以下程序将 10 个长度为 4000 个字符的 varchar 变量合并到一个 CLOB 中:
procedure insert_iec_by_parts(p_header_id in number,
p_contents_part1 in varchar2,
p_contents_part2 in varchar2,
p_contents_part3 in varchar2,
p_contents_part4 in varchar2,
p_contents_part5 in varchar2,
p_contents_part6 in varchar2,
p_contents_part7 in varchar2,
p_contents_part8 in varchar2,
p_contents_part9 in varchar2,
p_contents_part10 in varchar2,
o_cur_results out sys_refcursor,
result_code out number) is
l_clob clob;
begin
l_clob:=p_contents_part1||p_contents_part2||p_contents_part3||p_contents_part4||p_contents_part5||
p_contents_part6||p_contents_part7||p_contents_part8||p_contents_part9||p_contents_part10;
insert_iec(p_header_id, l_clob, o_cur_results, result_code );
end;
procedure insert_iec(p_header_id in number,
p_contents in clob,
o_cur_results out sys_refcursor,
result_code out number) is
id_temp number;
l_id number;
procedure SetError(pErrCode number) is
-- A centralised sub proc could allow for a quick change to raise_application_error at any time.
begin
result_code := pErrCode;
end;
begin
select count(*) into l_id from log_sync_calls_headers
where log_sync_calls_headers.id =p_header_id;
case
when (p_header_id is null) or (l_id <= 0) then SetError(9804);
when p_contents is null then SetError(9805);
else
-- fetch sequence number
id_temp := iec_seq.nextval;
result_code:=0;
open o_cur_results for
select id_temp as id
from dual;
insert into log_sync_calls_iecs
(id, header_id, contents)
values
(id_temp, p_header_id, p_contents );
commit;
end case;
exception when others then
result_code :=9701;
rollback;
pkg_common.insert_log_record(p_source => 'insert_iec',
p_type => 'Er',
p_message => sqlerrm);
end;
当合并 10 个 4000 个字符的 varchar 变量时,程序工作正常。但是,我想将它扩展到 20 个长度为 4000 个字符的 varchar 变量。
当我尝试这样做时,出现以下错误:
ORA 06502: character string buffer too small.
谁能告诉我如何将这个过程扩展到 20 个长度为 4000 个字符的 varchar 变量?
像这个问题一样使用DBMS_LOB.APPEND函数(或者只在SO中搜索DBMS_LOB.APPEND):how to insert long string oracle clob or blob
你应该使用 DBMS_LOB
包。
首先你应该创建一个 clob 对象,否则你的变量没有被初始化
dbms_lob.createtemporary(l_clob ,true);
现在您可以使用 append
过程
dbms_lob.append(l_clob, p_contents_part1 );
完成后,不要忘记释放 clob 内存并销毁 clob 对象
dbms_lob.freetemporary(l_clob);
我有以下程序将 10 个长度为 4000 个字符的 varchar 变量合并到一个 CLOB 中:
procedure insert_iec_by_parts(p_header_id in number,
p_contents_part1 in varchar2,
p_contents_part2 in varchar2,
p_contents_part3 in varchar2,
p_contents_part4 in varchar2,
p_contents_part5 in varchar2,
p_contents_part6 in varchar2,
p_contents_part7 in varchar2,
p_contents_part8 in varchar2,
p_contents_part9 in varchar2,
p_contents_part10 in varchar2,
o_cur_results out sys_refcursor,
result_code out number) is
l_clob clob;
begin
l_clob:=p_contents_part1||p_contents_part2||p_contents_part3||p_contents_part4||p_contents_part5||
p_contents_part6||p_contents_part7||p_contents_part8||p_contents_part9||p_contents_part10;
insert_iec(p_header_id, l_clob, o_cur_results, result_code );
end;
procedure insert_iec(p_header_id in number,
p_contents in clob,
o_cur_results out sys_refcursor,
result_code out number) is
id_temp number;
l_id number;
procedure SetError(pErrCode number) is
-- A centralised sub proc could allow for a quick change to raise_application_error at any time.
begin
result_code := pErrCode;
end;
begin
select count(*) into l_id from log_sync_calls_headers
where log_sync_calls_headers.id =p_header_id;
case
when (p_header_id is null) or (l_id <= 0) then SetError(9804);
when p_contents is null then SetError(9805);
else
-- fetch sequence number
id_temp := iec_seq.nextval;
result_code:=0;
open o_cur_results for
select id_temp as id
from dual;
insert into log_sync_calls_iecs
(id, header_id, contents)
values
(id_temp, p_header_id, p_contents );
commit;
end case;
exception when others then
result_code :=9701;
rollback;
pkg_common.insert_log_record(p_source => 'insert_iec',
p_type => 'Er',
p_message => sqlerrm);
end;
当合并 10 个 4000 个字符的 varchar 变量时,程序工作正常。但是,我想将它扩展到 20 个长度为 4000 个字符的 varchar 变量。
当我尝试这样做时,出现以下错误:
ORA 06502: character string buffer too small.
谁能告诉我如何将这个过程扩展到 20 个长度为 4000 个字符的 varchar 变量?
像这个问题一样使用DBMS_LOB.APPEND函数(或者只在SO中搜索DBMS_LOB.APPEND):how to insert long string oracle clob or blob
你应该使用 DBMS_LOB
包。
首先你应该创建一个 clob 对象,否则你的变量没有被初始化
dbms_lob.createtemporary(l_clob ,true);
现在您可以使用 append
过程
dbms_lob.append(l_clob, p_contents_part1 );
完成后,不要忘记释放 clob 内存并销毁 clob 对象
dbms_lob.freetemporary(l_clob);