Saturday, October 3, 2009

Steps to upload GIF, XLS, PDF, JPG and DOC files into oracle database

Step 1
======
Create or replace directory my_files as '/usr/temp';
Create table demo(sno number, filedata blob);
Copy any file (jpg,gif,pdf,xls....) into /usr/temp
Execute the below code. Change the file name according to your requirement

Step 2
======
declare
l_blob blob;
l_bfile bfile;
begin
insert into demo values ( 3, empty_blob() )
returning filedata into l_blob;
l_bfile := bfilename( 'MY_FILES', 'water.jpg' );
dbms_lob.fileopen( l_bfile );
dbms_lob.loadfromfile( l_blob, l_bfile, dbms_lob.getlength( l_bfile ) );
dbms_lob.fileclose( l_bfile );
commit;
end;
Step 3
======
Check the file length to ensure whether file loaded successfully or not
Select sno,dbms_lob.getlength(filedata) from demo
Reference: http://www.sql.ru/forum/actualthread.aspx?tid=202867

No comments:

Post a Comment

Blog Archive