Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何使用insert语法将图片插入Oracle表中的BLOB列?_Sql_Oracle_Oracle11g_Sql Insert - Fatal编程技术网

Sql 如何使用insert语法将图片插入Oracle表中的BLOB列?

Sql 如何使用insert语法将图片插入Oracle表中的BLOB列?,sql,oracle,oracle11g,sql-insert,Sql,Oracle,Oracle11g,Sql Insert,我有一个简单的表格,我想在其中插入机器上存在的图像。我想将图片插入表格的BLOB列。只是想知道我该怎么做。我知道有一些现有的解决方案与BLOB相关,但没有一个通过使用INSERT语法直接帮助我 CREATE TABLE test(id int,photo BLOB); INSERT INTO test VALUES(1,'Path of the picture\filename'); 首先,创建一个目录来存储图像,并向用户授予读写权限。然后可以使用BFILENAME函数插入图像 SQL>

我有一个简单的表格,我想在其中插入机器上存在的图像。我想将图片插入表格的BLOB列。只是想知道我该怎么做。我知道有一些现有的解决方案与BLOB相关,但没有一个通过使用INSERT语法直接帮助我

CREATE TABLE test(id int,photo BLOB);

INSERT INTO test VALUES(1,'Path of the picture\filename');

首先,创建一个目录来存储图像,并向用户授予读写权限。然后可以使用BFILENAME函数插入图像

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.
现在,要存储给定图像,可以使用以下insert语句

[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.

参考资料:

这有帮助吗?那没用。。。我已经检查了链接。简单插入有什么问题?您的代码是正常的,除了照片列值。插入blob值,而不是路径。