如何使用INSERT语法在Oracle表的BLOB列中插入图片? [英] How to insert a picture into BLOB column in Oracle table using INSERT syntax?
问题描述
我有一个简单的表,我想在其中插入机器上存在的图像,我想将图片插入到表的BLOB列中.只是想知道我该怎么做.我知道有一些与BLOB相关的现有解决方案,但没有一个通过使用INSERT SYNTAX直接为我提供了帮助.
I have a simple table where I want to insert an image that exists on my machine.I would like to insert the picture into my table's BLOB column. Just wondering how can I do it. I understand that there are some existing solutions which are related to BLOB but none have helped me directly by using INSERT SYNTAX.
CREATE TABLE test(id int,photo BLOB);
INSERT INTO test VALUES(1,'Path of the picture\filename');
推荐答案
首先,创建一个目录来存储图像并向用户授予读取,写入权限.然后,您可以使用BFILENAME函数插入图像.
First of all, create a directory to store images and grant read, write permission to the user. Then you can use BFILENAME function to insert the image.
SQL> conn / as sysdba
SQL> create directory image_dir as '/home/oracle/Desktop/';
Directory created.
SQL> grant read, write on directory image_dir to jay;
Grant succeeded.
SQL> conn jay
Enter password:
Connected.
SQL> CREATE TABLE test(id number, image blob);
Table created.
现在,要存储给定图像,可以使用以下插入语句.
Now, to store the give image can use the following insert statement.
[oracle@myserver Desktop]$ ls -l | grep abc
-rw-r--r-- 1 oracle oinstall 269748 Apr 16 01:23 abc.png
SQL> INSERT INTO test VALUES(1,bfilename('IMAGE_DIR','abc.png'));
1 row created.
参考: BFILENAME
这篇关于如何使用INSERT语法在Oracle表的BLOB列中插入图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!