Home  >  Article  >  Database  >  往Oracle数据库插入图形文件blob

往Oracle数据库插入图形文件blob

WBOY
WBOYOriginal
2016-06-07 17:07:271132browse

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;

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn