plsql - How convert CLOB to BLOB in Oracle? -
firstly converted blob of image clob, , converted clob blob. cannot see reconverted image. how can solve problem?
blob_to_clob function:
create or replace function blob_to_clob (blob_in in blob) return clob v_clob clob; v_varchar varchar2(32767); v_start pls_integer := 1; v_buffer pls_integer := 32767; begin dbms_lob.createtemporary(v_clob, true); in 1..ceil(dbms_lob.getlength(blob_in) / v_buffer) loop v_varchar := utl_raw.cast_to_varchar2(dbms_lob.substr(blob_in, v_buffer, v_start)); dbms_lob.writeappend(v_clob, length(v_varchar), v_varchar); v_start := v_start + v_buffer; end loop; return v_clob; end blob_to_clob;
clob_to_blob function:
create or replace function clob_to_blob2(p_clob in clob) return blob v_blob blob; v_offset number default 1; v_amount number default 4096; v_offsetwrite number default 1; v_amountwrite number; v_buffer varchar2(4096 char); begin dbms_lob.createtemporary(v_blob, true); begin loop dbms_lob.read (lob_loc => p_clob, amount => v_amount, offset => v_offset, buffer => v_buffer); v_amountwrite := utl_raw.length (r => utl_raw.cast_to_raw(c => v_buffer)); dbms_lob.write (lob_loc => v_blob, amount => v_amountwrite, offset => v_offsetwrite, buffer => utl_raw.cast_to_raw(v_buffer)); v_offsetwrite := v_offsetwrite + v_amountwrite; v_offset := v_offset + v_amount; v_amount := 4096; end loop; exception when no_data_found null; end; return v_blob; end clob_to_blob2;
code perform minimal recoding:
create or replace function clob2blob(aclob clob) return blob result blob; o1 integer; o2 integer; c integer; w integer; begin o1 := 1; o2 := 1; c := 0; w := 0; dbms_lob.createtemporary(result, true); dbms_lob.converttoblob(result, aclob, length(aclob), o1, o2, 0, c, w); return(result); end clob2blob; /
but clob can not contain image data without encoding base64
Comments
Post a Comment