create table test
(
id number primary key,
docs BLOB
);
create or replace directory doc_loc
as 'c:\test';
CREATE OR REPLACE PROCEDURE Load_BLOB_From_File (file_name in varchar2)
AS
src_loc bfile:= bfilename('DOC_LOC',Load_BLOB_From_File.file_name);
dest_loc BLOB;
begin
insert into test values(1,empty_blob()) returning docs
into dest_loc;
dbms_lob.open(src_loc,DBMS_LOB.LOB_READONLY);
DBMS_LOB.OPEN(dest_loc, DBMS_LOB.LOB_READWRITE);
DBMS_LOB.LOADFROMFILE(
dest_lob => dest_loc
,src_lob => src_loc
,amount => DBMS_LOB.getLength(src_loc));
DBMS_LOB.CLOSE(dest_loc);
DBMS_LOB.CLOSE(src_loc);
COMMIT;
end;
/
show errors;
exec Load_BLOB_From_File('test.pdf');
No comments:
Post a Comment