[ORACLE] CLOB -> BLOB function

|

CREATE OR REPLACE FUNCTION CLOB2BLOB (p_clob in CLOB)
return BLOB
is
-- transforming CLOB a BLOB
p_blob blob;
l_off number default 1;
l_amt number default 4096;
l_offWrite number default 1;
l_amtWrite number;
l_str varchar2(4096 char);
begin
DBMS_LOB.CREATETEMPORARY(p_blob, TRUE);
begin
loop
dbms_lob.read ( p_clob, l_amt, l_off, l_str );

l_amtWrite := utl_raw.length ( utl_raw.cast_to_raw( l_str) );
dbms_lob.write( p_blob, l_amtWrite, l_offWrite,
utl_raw.cast_to_raw( l_str ) );

l_offWrite := l_offWrite + l_amtWrite;

l_off := l_off + l_amt;
l_amt := 4096;
end loop;
exception
when no_data_found then
NULL;
end;
return p_blob;
end CLOB2BLOB;
/

And