ITPub博客

首页 > 数据库 > Oracle > Oracle插入Blob数据的方法

Oracle插入Blob数据的方法

原创 Oracle 作者:zhenghaishu 时间:2015-10-16 16:26:50 0 删除 编辑


Oracle插入Blob数据的方法


 


create table test20151016(a blob);


create or replace directory tmp as 'e:\';


 


--建立PL/SQL块


declare


b_file bfile;


b_lob  blob;


begin


--return a into b_lob将该列与一个blog类型的变量绑定在一起,以后只要为b_lob赋值,即等于将该值插入了表中


insert into test20151016(a) values(empty_blob()) return a into b_lob;


 


--TMP是建立的文件所在的目录,一定要大写;test.png是文件名;将文件转换为bfile


b_file := bfilename('TMP', 'test.png');


dbms_lob.open(b_file, dbms_lob.file_readonly);


 


-- 将b_file中的内容转换到b_lob


dbms_lob.loadfromfile(b_lob,b_file,dbms_lob.getlength(b_file));


    dbms_lob.close(b_file);


    commit;


end;


/


 


 


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29485627/viewspace-1814547/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-02-14

  • 博文量
    112
  • 访问量
    1057345