将CLOB分成几部分

时间:2019-05-15 11:46:46

标签: plsql clob

我有下表:

LOG_SYNC_CALLS_HEADERS
    ID
    CALL_DATE
    CALL_TYPE (foreign key to LOG_SYNC_CALL_TYPES)
    ACTION_NAME
    ACTION_RESULTS
LOG_SYNC_CALLS_IECS
    ID
    HEADER_ID (foreign key to LOG_SYNC_CALLS_HEADERS)
    CONTENTS (clob)

我需要创建过程GET_IEC_BY_PARTS。输入参数将是ID,对于该ID,您必须在表LOG_SYNC_CALLS_IECS中找到对应的CLOB。将varchar中的CLOB分隔为4000个字符,然后在游标中将其返回。游标包含以下列:ID,HEADER_ID,PART_NUMBER,CONTENTS。 PART_NUMBER的范围是1到10。

有人可以告诉我如何执行此过程吗?

我的问题是:

  1. 如何将varchar中的CLOB分隔为4000个字符并在游标中将其返回?

  2. 如何为光标定义参数?

我有以下步骤:

INSERT_IEC_BY_PARTS。该过程具有参数:ID(NUMBER),HEADER_ID(NUMBER),CONTENTS_PART1,...,CONTENTS_PART10。 CONTENT_PART是VARCHAR类型。该过程返回result_code号,并在光标中插入ID(OUT参数)。

此过程应将这10个CONTENTS_PART合并为一个CLOB,然后使用INSERT_IEC过程将该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;

INSERT_IEC:

 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;

0 个答案:

没有答案