You have to read "Oracle® Database Application Developer's Guide - Large Objects".
http://mordor.tengry.com/db/oracle/d...b10796/toc.htm
This code from manual with some change:
-------------------------------0------------------------------------------
first of all create directory(don't forget about right of user) and table:
-- Create directory
create or replace directory UTL_DBMS_LOB
as 'c:\oracle\product\10.1.0\admin\orcl\utl_dbms_lob' ;
-- Create table
create table DOCUMENT
(
ID NUMBER not null,
CREATIONDATE DATE not null,
PUBLISHDATE DATE not null,
AUTHOR VARCHAR2(50) not null,
DOC BLOB not null
);
-- Create/Recreate primary, unique and foreign key constraints
alter table DOCUMENT
add constraint PK_DOCUMENT primary key (ID);
--------------------------------1---------------------------------------------
CREATE OR REPLACE PROCEDURE loadBLOB_proc (dst_loc IN OUT BLOB, blobfilename IN VARCHAR2) IS
src_loc BFILE := bfilename('UTL_DBMS_LOB', blobfilename) ;
src_offset NUMBER := 1;
dst_offset NUMBER := 1;
src_osin NUMBER;
dst_osin NUMBER;
bytes_rd NUMBER;
bytes_wt NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE('------------ LOB LOADBLOBFORMFILE EXAMPLE------------');
/* Opening the source BFILE is mandatory */
dbms_lob.fileopen(src_loc, dbms_lob.file_readonly);
/* Opening the LOB is optional */
dbms_lob.OPEN(dst_loc, dbms_lob.lob_readwrite);
/* Save the input source/destination offsets */
src_osin := src_offset;
dst_osin := dst_offset;
/* Use LOBMAXSIZE to indicate loading the entire BFILE */
dbms_lob.LOADBLOBFROMFILE(dst_loc,src_loc,dbms_lob .lobmaxsize,src_offset,dst_offset) ;
/* Closing the LOB is mandatory if you have opened it */
dbms_lob.close(dst_loc);
dbms_lob.filecloseall();
/* Use the src_offset returned to calculate the actual amount read from the
BFILE */
bytes_rd := src_offset - src_osin;
dbms_output.put_line(' Number of bytes read from the BFILE ' || bytes_rd ) ;
/* Use the dst_offset returned to calculate the actual amount written to the
BLOB */
bytes_wt := dst_offset - dst_osin;
dbms_output.put_line(' Number of bytes written to the BLOB ' || bytes_wt ) ;
/* If there is no exception the number of bytes read should equal to the
number of bytes written */
end ;
------------------------------2----------------------------------------------
now you can call loadBLOB_proc using this code:
declare
id integer;
dst_loc BLOB; --locator
blobfilename varchar2(50);
begin
id:=1;
blobfilename := 'file.jpg';
insert into document(id,creationdate,publishdate,author,doc)
values (id,sysdate,sysdate,'_AP',empty_BLOB())
returning doc into dst_loc;
loadBLOB_proc (dst_loc, blobfilename ) ;
end ;