How to convert CLOB to varchar2 whose length is more than 4000
960627Sep 7 2012 — edited Oct 1 2012Hi ,
I have to retrive the CLOB data into varchar2 and spilt those comma seperated values into rows
but i am getting following error
" ORA-06502: PL/SQL: numeric or value error: character string buffer too small "
the proc i used is like following :
: create table test_clob (grp_id CLOB, id number)
Create or replace proc test_clob(p_id number )
Is
V_clob CLOB;
V_str varchar2(4000);
V_main varchar2(30000);
TYPE t_clob IS REF CURSOR;
cur_clob t_clob;
Begin
Select grp_id
Into v_str
From test_clob
Where id= p_id;
---converting column data in rows as I have to return the cursor as output
V_main:= ' select grp_id from ( WITH t AS
(SELECT REGEXP_SUBSTR(''' || v_str ||
''', ''[^,]+'', 1, LEVEL) txt
FROM DUAL
CONNECT BY LEVEL <=
LENGTH(''' || v_str ||
''') -
LENGTH(REPLACE(''' || v_str ||
''', '','')) + 1)
SELECT REGEXP_SUBSTR(trim(txt), ''[^\,]+'', 1, 1) grp_id
FROM t )';
open cur_clob for ' select rtrim(xmlagg(xmlelement(e, grp_id || '','')).extract (''//text()'').getclobval (),'','') grp_id
from ( '|| v_main||' ) ';
loop
fetch cur_clob
into V_clob;
exit when cur_clob %notfound;
end loop;
insert into test_clob
values (p_id, v_clob);
commit;
End;
Please help its very urgent