Load a file : DBMS_LOB « System Packages « Oracle PL/SQL Tutorial






SQL>
SQL> set echo on
SQL>
SQL> create table demo
  2  ( id           int primary key,
  3    theBlob      blob
  4  )
  5  /

Table created.

SQL>
SQL> create or replace directory my_files as 'c:\temp\';

Directory created.

SQL>
SQL> create sequence blob_seq;

Sequence created.

SQL>
SQL>
SQL> create or replace procedure load_a_file( p_dir_name in varchar2,p_file_name in varchar2) as
  2      l_blob    blob;
  3      l_bfile   bfile;
  4  begin
  5      insert into demo values ( blob_seq.nextval, empty_blob() )
  6      returning theBlob into l_Blob;
  7
  8      l_bfile := bfilename( p_dir_name, p_file_name );
  9      dbms_lob.fileopen( l_bfile );
 10
 11      dbms_lob.loadfromfile( l_blob, l_bfile,dbms_lob.getlength( l_bfile ) );
 12      dbms_lob.fileclose( l_bfile );
 13  end;
 14  /

Procedure created.

SQL>
SQL> exec load_a_file( 'MY_FILES', 'clean.sql' );
BEGIN load_a_file( 'MY_FILES', 'clean.sql' ); END;

*
ERROR at line 1:
ORA-22288: file or LOB operation FILEOPEN failed
The system cannot find the path specified.
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "JAVA2S.LOAD_A_FILE", line 9
ORA-06512: at line 1


SQL>
SQL> drop table demo;

Table dropped.

SQL> drop sequence blob_seq;

Sequence dropped.

SQL>








31.12.DBMS_LOB
31.12.1.DBMS_LOB Package
31.12.2.Print clob data out
31.12.3.Use dbms_lob.getlength to get the length of a clob data
31.12.4.Show Java source file
31.12.5.Use dbms_lob package to deal with clob data
31.12.6.Use dbms_lob.getlength and dbms_lob.substr with blob type column
31.12.7.Use dbms_lob.substr to get part of clob data
31.12.8.DBMS_LOB.READ
31.12.9.Load a file