blob对象可以存储图片, 音频, 影视等二进制文件。
1:创建目录, 也就是你要提取的数据存储的目录
create directory lcc_dir as 'C:\dir';
2:创建用户
create user lcc identified by 123;
3:给用户授权
grant read, write on directory lcc_dir to lcc;
4:创建存储blob对象的表:
create table blob_tb(
data_name varchar2(10),
blob_file blob
);
5:创建存储过程
create or replace procedure load_blob(fname varchar2) as
srcfile bfile;
dstfile blob;
begin
srcfile := bfilename('LCC_DIR', fname);
insert into blob_tb values(fname, empty_blob());
select blob_file into dstfile from blob_tb where data_name = fname for update;
dbms_lob.fileopen(srcfile);
dbms_lob.loadfromfile(dstfile, srcfile, dbms_lob.getlength(srcfile));
update blob_tb set blob_file = dstfile where data_name = fname;
dbms_lob.fileclose(srcfile);
end;
/