How to insert a picture into BLOB column in Oracle table using INSERT syntax?

試著忘記壹切 提交于 2020-01-07 07:49:32

问题


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');

回答1:


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.

Reference: BFILENAME



来源:https://stackoverflow.com/questions/43432415/how-to-insert-a-picture-into-blob-column-in-oracle-table-using-insert-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!