package body ted_p1026 is
function column_long_to_clob
( p_table_or_view_name in varchar2
, p_column_name in varchar2
, p_where_clause in varchar2
)
return clob
is
v_stmt varchar2(2000);
v_cursor integer := dbms_sql.open_cursor;
v_value_length pls_integer;
v_fetch_offset pls_integer := 0;
v_fetch_bytes pls_integer := 32000;
v_fetch_chunk varchar2(32000);
v_result clob;
begin
dbms_lob.createtemporary(lob_loc => v_result, cache => true);
v_stmt :=
'select ' || p_column_name || chr(10)
|| 'from ' || p_table_or_view_name || chr(10)
|| 'where ' || nvl(p_where_clause, '1=1')
;
dbms_sql.parse
( c => v_cursor
, statement => v_stmt
, language_flag => dbms_sql.native
)
;
dbms_sql.define_column_long
( c => v_cursor
, position => 1
)
;
if dbms_sql.execute_and_fetch(v_cursor) = 1 then
loop
dbms_sql.column_value_long
( c => v_cursor
, position => 1
, length => v_fetch_bytes
, offset => v_fetch_offset
, value => v_fetch_chunk
, value_length => v_value_length
)
;
if v_value_length = 0 then exit; end if;
dbms_lob.append(dest_lob => v_result, src_lob => v_fetch_chunk);
v_fetch_offset := v_fetch_offset + v_fetch_bytes;
end loop;
end if;
if dbms_sql.is_open(v_cursor) then
dbms_sql.close_cursor(v_cursor);
end if;
return v_result;
end column_long_to_clob;
end ted_p1026;