时间:2021-07-01 10:21:17 帮助过:21人阅读
create table Image_lob(t_id varchar2(5),t_image blob); create or replace directory images as
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:\temp\pic''';
v_sql := 'create or replace directory IMAGES_BAK as '||v_path; --路径必须是大小写,Oracle对这个是敏感的
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;
,