如何使用绑定变量在表中插入大数据

时间:2016-08-01 13:42:49

标签: sql xml oracle

我正在尝试将长度为43000的大型xml文件插入<img ng-src="https://someimageurl/{{ foo.replace('bar','') }} />

asktom使用绑定变量进行了remcomanded,但其链接已被破坏。

所以我的问题是如何在绑定变量中插入大型xml文件。这是我的程序

clob

我想分割长度,以便将它们插入表格

2 个答案:

答案 0 :(得分:1)

我不知道你为什么要将CLOB拆分成4k块用于存储,因为你的价值已经很高兴地存储为CLOB ...但如果你真的想要,你可以使用分层查询:

create or replace procedure sp_insert_xml (p_id in int) as
  l_xml clob;
  l_len pls_integer;
  l_chunksize pls_integer := 4000;
begin
  select xml into l_xml from process_d where process_id = p_id;

  l_len := dbms_lob.getlength(l_xml);
  dbms_output.put_line(l_len);

  insert into test_id (id, chunk_id, chunk_text)
  select p_id, level, dbms_lob.substr(l_xml, l_chunksize, (l_chunksize * (level - 1)) + 1)
  from dual connect by level <= ceil(l_len / l_chunksize);
end;
/

或者您可以使用递归子查询因子或PL / SQL循环:

  for l_chunk_id in 0..floor(l_len/l_chunksize) loop
    insert into test_id (id, chunk_id, chunk_text)
    values (p_id, l_chunk_id,
      dbms_lob.substr(l_xml, l_chunksize, (l_chunksize * l_chunk_id) + 1));
  end loop;

但是使用递归CTE或connect-by,你真的不需要一个过程,你可以在纯SQL中完成。

答案 1 :(得分:1)

Try to use sqlldr insted of sqlplus. You don't need to chunk lob into smaller pcises

 1. Save your clobs into files(test.xml,test2.xml)

 2. On destination DB create destination table

    create table clob_table( name varchar2(100), doc clob);

 3. create control file for sqlldr.



    LOAD DATA 
    INFILE *
    append
       INTO TABLE clob_table
       FIELDS TERMINATED BY ','
       (name    char(100),
        doc      LOBFILE(name) TERMINATED BY EOF
        )
    BEGINDATA
    test.xml
    test2.xml


 5. execute sqlldr `sqlldr user/pass@dest_db control=load.ctl`