Home > Database > Mysql Tutorial > body text

在Oracle数据库的表中插入图片的方法

WBOY
Release: 2016-06-07 17:07:29
Original
1415 people have browsed it

有些同学的项目中需要在表中插入图片,下面提供一种方法供大家参考: 1、创建表,注意:插入图片的列要定义成BLOB类型 create

有些同学的项目中需要在表中插入图片,下面提供一种方法供大家参考:

1、创建表,注意:插入图片的列要定义成BLOB类型

  create table image_lob(t_id varchar2(5) not null,t_image blob not null);

2、创建图片目录,images为目录名

  create or replace directory "images" as 'f:\pic\';

3、创建存储过程,filename为图片的名字,如‘cat.jpg’

create or replace procedure img_insert(tid varchar2,filename varchar2)as
f_lob bfile;
b_lob blob;
begin
insert into image_lob(t_id,t_image)
values(tid,empty_blob())return t_image into b_lob;
f_lob:=bfilename('images',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;
/

4、执行上面的存储过程,实现图片的插入

exec img_insert('1','cat.jpg');


5、查看表

select * from image_lob;

linux

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!