Wednesday, October 21, 2009

Data Convert From CLOB to BLOB

CREATE OR REPLACE Function Fnc_Clob_to_Blob (P_clob_in in clob)
Return blob

is
v_blob blob;
v_offset integer;
v_buffer_varchar varchar2(32000);
v_buffer_raw raw(32000);
v_buffer_size binary_integer := 32000;

Begin
--
If p_clob_in is null Then
return null;
End If;
--
DBMS_LOB.CREATETEMPORARY(v_blob, TRUE);
v_offset := 1;

FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(p_clob_in) / v_buffer_size)

Loop

dbms_lob.read(p_clob_in, v_buffer_size, v_offset, v_buffer_varchar);
v_buffer_raw := utl_raw.cast_to_raw(v_buffer_varchar);

dbms_lob.writeappend(v_blob, utl_raw.length(v_buffer_raw), v_buffer_raw);
v_offset := v_offset + v_buffer_size;

End Loop;

Return v_blob;

End Fnc_Clob_to_Blob;
/

No comments:

Post a Comment