如何将图片字段插入表格? [英] How to insert picture field into table?
本文介绍了如何将图片字段插入表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<br />
sql>CREATE TABLE lob_table (id NUMBER, doc BLOB);<br />
<br />
Table created<br />
sql>INSERT INTO lob_table VALUES (1, EMPTY_BLOB());<br />
<br />
1 row created<br />
<br />
sql>DECLARE<br />
2 src_lob BFILE := BFILENAME(''image_dir'', ''D:\image_dir\image1.jpeg'');<br />
3 dest_lob BLOB;<br />
4 BEGIN<br />
5 INSERT INTO lob_table VALUES(2, EMPTY_BLOB())<br />
6 RETURNING doc INTO dest_lob;<br />
7 DBMS_LOB.OPEN(src_lob, DBMS_LOB.LOB_READONLY);<br />
8 DBMS_LOB.LoadFromFile( DEST_LOB => dest_lob,<br />
9 SRC_LOB => src_lob,<br />
10 AMOUNT => DBMS_LOB.GETLENGTH(src_lob) );<br />
11 DBMS_LOB.CLOSE(src_lob);<br />
12 COMMIT;<br />
13 END;<br />
14 /<br />
<br />
<br />
dbms_lob.close(src_lob);<br />
*<br />
ERROR at line 11:<br />
ORA-06550: line 11, column 1:<br />
PLS-00103: Encountered the symbol "DBMS_LOB" when expecting one of the<br />
following:<br />
:= . ( % ;<br />
程序中发生此类错误
请帮助
This kind of error occurred in procedure
Please help
推荐答案
下面是将图像插入表中的代码。
创建一个表来存储blob 。
Below is the code to insert an image into the table.
Create a table to store the blob.
CREATE TABLE tabblobs
( id varchar2(255),
blob_col blob
);
在数据库中创建逻辑目录。
Create a logical directory in the database.
CREATE OR REPLACE directory MY_FILES AS 'd:\images';
使用逻辑
目录创建一个从物理磁盘加载blob的过程.gif ORATEST.gif必须存在于d:\ images.
Create a procedure to load the blob from the physical disk using the logical
directory. The gif "ORATEST.gif" must exist in d:\images.
CREATE OR REPLACE procedure insert_img AS
flob bfile;
blob blob;
BEGIN
INSERT INTO tabblobs VALUES ( 'MyGif', empty_blob() )
RETURN blob_col INTO blob;
flob := bfilename( 'MY_FILES', 'ORATEST.gif' );
dbms_lob.fileopen(flob, dbms_lob.file_readonly);
dbms_lob.loadfromfile( blob, flob, dbms_lob.getlength(flob) );
dbms_lob.fileclose(flob);
COMMIT;
END;
/
这篇关于如何将图片字段插入表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文