Oracle PL/SQL library BLOB_WRAPPER: Write a blob into a file

This is an example on how BLOB_WRAPPER can be used to write a blob into a file.
First, a blob is created that consists of 400 lines with 400 characters each (out_width). The characters in the blob are either xes or spaces, so that the x create a circle.
Finally, the blob is written into a file
  out_width  number       := 400;
  radius     number       := 300;
  dir        varchar2(30) :='LOB_TEST_DIR';
  file       varchar2(30) :='circle.txt';

  some_lob blob;
  one_byte raw(1);


  some_lob := empty_blob();
  dbms_lob.createTemporary(some_lob, true);, dbms_lob.lob_readwrite);

  for x in -out_width/2 .. out_width/2 loop /*{*/
      for y in -out_width/2 .. out_width/2 loop/*{*/

          if sqrt(x*x + y*y) > radius/2 then
            one_byte := utl_raw.cast_to_raw(' ');
            one_byte := utl_raw.cast_to_raw('X');
          end if;
          dbms_lob.append(some_lob, one_byte);

      end loop; /*}*/
      one_byte := utl_raw.cast_to_raw(chr(10));
      dbms_lob.append(some_lob, one_byte);
  end loop;/*}*/

  blob_wrapper.to_file(dir, file, some_lob);

end write_circle;
The source code for this exaple is on github.
Go back to library's main page