【问题标题】:Merging varchars into one CLOB将 varchar 合并为一个 CLOB
【发布时间】:2019-05-16 06:17:14
【问题描述】:

我有以下过程将 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 个 varchar 变量(每个 4000 个字符)时,程序运行良好。但是,我想将其扩展到 20 个长度为 4000 个字符的 varchar 变量。

当我尝试这样做时,它给了我以下错误:

ORA 06502: character string buffer too small.

有人可以告诉我如何能够将此过程扩展到 20 个长度为 4000 个字符的 varchar 变量吗?

【问题讨论】:

    标签: plsql clob


    【解决方案1】:

    在这个问题中使用 DBMS_LOB.APPEND 函数(或者只在 SO 中搜索 DBMS_LOB.APPEND):how to insert long string oracle clob or blob

    【讨论】:

    • 我试过了,它给了我错误:指定的 LOB 定位器无效。你知道如何解决这个错误吗?
    • 我使用了 DBMS_LOB.CREATETEMPORARY(LINE,true);现在它可以工作了。谢谢。
    • @user11153823:如果它帮助您前进,请您接受解决方案。谢谢。每一点都很重要:)
    • 你能给我解释一下相反的过程吗?如何将 clob 拆分为 varchar 变量?
    • @user11153823:为什么不提出这个主题的问题。反正我正在调查...
    【解决方案2】:

    您应该使用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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-21
      • 2013-01-30
      • 2023-03-12
      • 1970-01-01
      • 2020-04-16
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      相关资源
      最近更新 更多