日期:2014-05-17  浏览次数:20993 次

存储过程如何按行读取CLOB内容
存储过程如何按行读取CLOB内容,要把每行的内容取出来后,存到一个变量里,然后插入到表里。

clob字段里的内容是这样的:
11.11.11.11
22.22.22.22
33.33.33.33
44.44.44.44
55.55.55.55/15:51.51.51.51
CLOB 按行读取

------解决方案--------------------

create table test_clob(id integer,info clob);
insert into test_clob values(2,'aaaaaaaaaa
bbbbbbbbbb
ccccccccccc
ddddddddd
eeeeeeeeeeee');
commit;
select * from test_clob;

declare 
vv_buf varchar2(32767);
vv_buf1 varchar2(32767);
i integer;
begin
   select t.info into vv_buf
   from test_clob t where t.id = 2;
   
   i := 1;
   while instr(vv_buf,chr(10),i) >= 1 loop
     vv_buf1 := substr(vv_buf,i,instr(vv_buf,chr(10),i)-i);
     i := instr(vv_buf,chr(10),i) + 1;
     dbms_output.put_line('---------------');
     dbms_output.put_line(vv_buf1);  
   end loop;
   if i <> length(vv_buf) then
     dbms_output.put_line('---------------');
     vv_buf1 := substr(vv_buf,i,length(vv_buf));
     dbms_output.put_line(vv_buf1);
   end if;
end;


不知道这个是否满足。