[置顶] 使用oracle压缩blob对象


1、使用oracle压缩blob对象

l_blob := utl_compress.lz_compress(l_blob);

2、将blob转换成clob
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   ;
    tmp_num     NUMBER ;
    BEGIN
    dbms_lob.createtemporary(v_clob,   TRUE );
    tmp_num := ceil(dbms_lob.getlength(blob_in) / v_buffer);
      IF   tmp_num >   0   THEN
        --防止传入的BLOB为NULL或长度为0时引发错误
        FOR   i   IN   1   .. tmp_num   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   ;
      END   IF   ;
      RETURN   v_clob;
    END   blob_to_clob;

3、将clob数据插入文件中
dbms_xslprocessor.clob2file(l_clob, p_dir_name, p_file_name);

你可能感兴趣的:(oracle,压缩,数据,对象,buffer)