我已经使用sqlplus为用户maciek定义了具有权限的文件夹。
SQL> CREATE OR REPLACE DIRECTORY test AS '\home\oracle\Desktop\test';
SQL> GRANT READ, WRITE ON DIRECTORY test to maciek;
我之前手动创建的文件夹。 当我运行以下脚本时。
DECLARE
OBRAZEK_lob blob;
obrazek_SI si_stillimage;
DANE_PLIKU BFILE := BFILENAME('test','Pojazd.jpg');
BEGIN
DBMS_LOB.CREATETEMPORARY(OBRAZEK_lob, TRUE);
DBMS_LOB.fileopen(DANE_PLIKU, DBMS_LOB.file_readonly);
DBMS_LOB.LOADFROMFILE(OBRAZEK_lob, DANE_PLIKU, DBMS_LOB.GETLENGTH(DANE_PLIKU));
DBMS_LOB.FILECLOSE(DANE_PLIKU);
obrazek_SI :=SI_stillimage(obrazek_lob);
INSERT INTO foto_oferty_si (idk,nazwa_pliku,opis,obrazek,oferta_id) VALUES(1, 'Pojazd.jpg','Autko', obrazek_si, 1);
DBMS_LOB.FREETEMPORARY(OBRAZEK_lob);
COMMIT;
END;
我收到以下错误消息。
Error report:
ORA-22285: non-existent directory or file for FILEOPEN operation
ORA-06512: at "SYS.DBMS_LOB", line 805
ORA-06512: at line 7
22285. 00000 - "non-existent directory or file for %s operation"
*Cause: Attempted to access a directory that does not exist, or attempted
问题是Oracle没有看到我手动创建的文件夹吗?按下面的命令创建自动指向路径的文件夹?
CREATE OR REPLACE DIRECTORY test AS '\home\oracle\Desktop\test';
答案 0 :(得分:1)
从评论中,您在VBox中使用Oracle数据库,并希望从主机桌面加载图像。
这是两个选项。
auto-mounted shared folders are mounted into the /media directory, along with the prefix sf_
制作此示例/ media / sf_klrice 在create directory命令中使用它。
VBox参考: https://www.virtualbox.org/manual/ch04.html#sf_mount_auto
使用允许JavaScript逻辑的SQLcl。代码不是PLSQL和目录,代码看起来就像下面的代码片段。我的博客上有一个更完整的写作和示例:http://krisrice.io/2015-10-14-sqlcl-blob-loading-from-file/
/*
* Function to take in a filename and add or create it to a map
* with bind variables
*/
function addBindToMap(map,bindName,fileName){
/* conn is the actual JDBC connection */
var b = conn.createBlob();
var out = b.setBinaryStream(1);
var path = java.nio.file.FileSystems.getDefault().getPath(fileName);
/* slurp the file over to the blob */
java.nio.file.Files.copy(path, out);
out.flush();
if ( map == null ) {
/* java objects as binds needs a hashmap */
var HashMap = Java.type("java.util.HashMap");
map = new HashMap();
}
/* put the bind into the map */
map.put("b",b);
return map;
}
/* File name */
var file = "/Users/klrice/workspace/raptor_common/10_5.log";
/* load binds */
binds = addBindToMap(null,"b",file);
/* add more binds */
binds.put("path",file);
/* exec the insert and pass binds */
var ret = util.execute("insert into k(path,blob_content,when) values(:path , :b, sysdate)",binds);
/* print the results */
sqlcl.setStmt("select path,dbms_lob.getlength(blob_content) from k order by when desc;");
sqlcl.run();
答案 1 :(得分:0)
有趣,但必须在capital letters
中指定oracle目录名称,使用TEST
代替test
。