FUNCTION blob2clob(p_blob IN BLOB) RETURN CLOB IS
v_clob CLOB;
v_amount NUMBER DEFAULT 2000;
v_offset NUMBER DEFAULT 1;
v_buffer VARCHAR2(32767);
v_length PLS_INTEGER := dbms_lob.getlength(p_blob);
BEGIN
dbms_lob.createtemporary(v_clob, TRUE);
dbms_lob.OPEN(v_clob, dbms_lob.lob_readwrite);
WHILE v_offset <= v_length LOOP
v_buffer := utl_raw.cast_to_varchar2(dbms_lob.substr(p_blob, v_amount, v_offset));
IF length(v_buffer) > 0 THEN
dbms_lob.writeappend(v_clob, length(v_buffer), v_buffer);
END IF;
v_offset := v_offset + v_amount;
EXIT WHEN v_offset > v_length;
END LOOP;
RETURN v_clob;
END blob2clob;
----------------------------------------------------------------
FUNCTION blob_to_clob (blob_in IN BLOB) RETURN CLOB
AS
v_clob CLOB;
v_varchar VARCHAR2(32767);
v_start PLS_INTEGER := 1;
v_buffer PLS_INTEGER := 32767;
BEGIN
DBMS_LOB.CREATETEMPORARY(v_clob, TRUE);
FOR i 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;
No comments:
Post a Comment