create table Image_lob(t_id varchar2(5),t_image blob);
create or replace directory images as 'E:image';
SELECT * FROM Image_lob;
create or replace procedure ima_insert(tid varchar2, filename varchar2,v_path varchar2) as
f_lob bfile;--文件类型
b_lob blob;
v_sql varchar2(4000);
begin
-- v_path := '''d:temppic''';
v_sql := 'create or replace directory as '||v_path;
dbms_output.put_line(v_sql);
execute immediate v_sql;
insert into image_lob(t_id,t_image) values(tid,empty_blob())return t_image into b_lob;
--插入空的blob
f_lob := bfilename('IMAGES_BAK',filename);
--获取指定目录下的文件
dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
--以只读的方式打开文件
dbms_lob.loadfromfile(b_lob,f_lob,dbms_lob.getlength(f_lob));
--传递对象
dbms_lob.fileclose(f_lob);
--关闭原始文件
commit;
end;
declare
begin
ima_insert('2','1.jpg','''E:image''');
end;