I am trying to read BLOB from Windows directory located on the Oracle 11g DB server:
create or replace directory BLOB_DIR as 'C:\data\images';
grant read, write on directory BLOB_DIR to public;
set serveroutput on;
declare
l_bfile BFILE;
begin
l_bfile := BFILENAME('BLOB_DIR', 'blob.jpg');
DBMS_LOB.fileopen(l_bfile, DBMS_LOB.file_readonly);
DBMS_LOB.fileclose(l_bfile);
end;
/
However, I am getting the following error:
ORA-22288: file or LOB operation FILEOPEN failed
ORA-06512: at "SYS.DBMS_LOB", line 744
ORA-06512: at line 5
I checked the directory and file exist and all the permissions are given to Everyone.
What am I doing wrong? How to get more specific error message?
Related
Below code is working perfectly in oracle 10g database
DECLARE
g_file_handle UTL_FILE.FILE_TYPE;
g_dir varchar2(100);
BEGIN
g_dir := Scamp_Utils.getutlfiledir;
DBMS_OUTPUT.PUT_LINE (g_dir);
g_file_handle := UTL_FILE.FOPEN (g_dir, 'qwe.txt', 'W', 32767);
UTL_FILE.PUT_LINE (g_file_handle, 'BEGINDATA');
UTL_FILE.FCLOSE (g_file_handle);
COMMIT;
END;
/
Here Scamp_Utils.getutlfiledir is a function which returns the path defined in utl_file_dir.
But same code doesn't work in oracle 12c database. I'm getting an error:
ORA-29280: invalid directory path
ORA-06512: at "SYS.UTL_FILE", line 41
ORA-06512: at "SYS.UTL_FILE", line 478
ORA-06512: at line 7
I have already provided rwx permission to all at the OS level. I'm still getting this error. I can use the oracle logical directory but I don't want to change code. What should I do here?
Oracle has two option to declare a directory for utl_file.
1. Change `utl_file_dir='/appl/flstadm/utl_files/wlsbb01'` in INIT.ORA file and restart DB. This solution is not recommended and deprecated.
2. Create directory object in DB.
CREATE OR REPLACE DIRECTORY my_dir AS '/appl/flstadm/utl_files/wlsbb01';
GRANT read, write ON DIRECTORY my_dir TO your_user;
g_file_handle := UTL_FILE.FOPEN ('my_dir', 'qwe.txt', 'W', 32767);
Have you added your path to init.ora?
I have following privileges CREATE ANY DIRECTORY, read, write on directory DOCS to user_name
I am using oracle 10g on Windows.
I have first created the directory as
CREATE DIRECTORY DOCS AS 'C:\Documents and Settings\Owner\Desktop\file';
Directory created successfully.
Now when I tried to execute following code
DECLARE
l_file UTL_FILE.file_type;
l_location VARCHAR2(100) := 'DOCS';
l_filename VARCHAR2(100) := 'test.pdf';
l_text VARCHAR2(32767);
BEGIN
-- Open file.
l_file := UTL_FILE.fopen(l_location, l_filename, 'r', 32767);
-- Read and output first line.
UTL_FILE.get_line(l_file, l_text, 32767);
dbms_output.put_line('First Line: |' || l_text || '|');
-- Close the file.
UTL_FILE.fclose(l_file);
END;
I get these errors
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 475
ORA-29283: invalid file operation
ORA-06512: at line 8
i don't have access to oracle on windows, but something like this in you init.ora file
UTL_FILE_DIR=c:\DOCS
you will then need to restart oracle
you should also be able to do the following (but i've not tested it)
alter system set utl_file_dir=c:\DOCS scope=both
I was learning PL/SQL and I have been getting this error as "invalid file operation since long"
The code is as follows:
SET SERVEROUTPUT on;
CREATE or replace directory DESKTOP as 'C:\Users\Gadre\Desktop';
declare
v1 varchar2(32767);
f1 utl_file.file_type;
begin
f1 :=utl_file.fopen('DESKTOP','test.docx','r');
dbms_output.put_line('HELLO WORLD');
end;
The error is:
Error report:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 5
29283. 00000 - "invalid file operation"
*Cause: An attempt was made to read from a file or directory that does
not exist, or file or directory access was denied by the
operating system.
*Action: Verify file and directory access privileges on the file system,
and if reading, verify that the file exists.
The file does exist surely. Plus I am through admin access so I think I do have privileges.
Hi I am running Oracle 11 and I am trying to write to a directory on the server box using UTL_FILE.FOPEN.
To test this I am using the following script (output included):
SQL> #D:\test.sql
declare
l_file_handle UTL_FILE.FILE_TYPE;
begin
l_file_handle := UTL_FILE.FOPEN('/appl/mydir',
'/appl/mydir/filename',
'W');
UTL_FILE.FCLOSE(l_file_handle);
DBMS_OUTPUT.PUT_LINE('FINISHED');
end;
ORA-29280: invalid directory path
ORA-06512: at "SYS.UTL_FILE", line 41
ORA-06512: at "SYS.UTL_FILE", line 478
ORA-06512: at line 7
SQL>
I have the /appl/mydir added to the UTL_FILE parameter:
SELECT value
FROM V$PARAMETER
WHERE NAME = 'utl_file_dir';
/appl/mydir, /appl/mydir2, /appl/mydir3
The UNIX directory is writable by all on UNIX:
$ ls -l /appl/mydir
total 0
drwxrwsrwx 2 user userc 363968 Nov 27 13:46 mydir
Using oracle Directory object is not an option and I am aware of the disadvantages of using the UTL_FILE_DIR implementation.
Any ideas why the above script is failing?
first, in 11g the preferred way is to create a directory and not use utl_file.
secondly, please verify what exact command you used to set the directoty list :
SELECT value
FROM V$PARAMETER
WHERE NAME = 'utl_file_dir';
/appl/mydir, /appl/mydir2, /appl/mydir3
was it
alter system set utl_file_dir='/appl/mydir, /appl/mydir2, /appl/mydir3' scope = spfile;
or
alter system set utl_file_dir='/appl/mydir','/appl/mydir2','/appl/mydir3' scope = spfile;
if its the first way, redo it again the 2nd way as the first way is wrong (it will look the same in the v$table output, but its wrong).
eg:
declare
2
l_file_handle UTL_FILE.FILE_TYPE;
4
begin
l_file_handle := UTL_FILE.FOPEN('/tmp/foo/a',
'/tmp/foo/a/filename.txt',
'w');
9
UTL_FILE.FCLOSE(l_file_handle);
11
DBMS_OUTPUT.PUT_LINE('FINISHED');
13
end;
15 /
declare
*
ERROR at line 1:
ORA-29280: invalid directory path
ORA-06512: at "SYS.UTL_FILE", line 41
ORA-06512: at "SYS.UTL_FILE", line 478
ORA-06512: at line 6
SQL> show parameter utl_fil
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
utl_file_dir string /tmp/foo, /tmp/foo/a
humm. now lets fix that data.
SQL> alter system set utl_file_dir='/tmp/foo','/tmp/foo/a' scope = spfile;
System altered.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup open
ORACLE instance started.
Total System Global Area 263049216 bytes
Fixed Size 2225584 bytes
Variable Size 176163408 bytes
Database Buffers 79691776 bytes
Redo Buffers 4968448 bytes
Database mounted.
Database opened.
declare
2
l_file_handle UTL_FILE.FILE_TYPE;
4
begin
l_file_handle := UTL_FILE.FOPEN('/tmp/foo/a',
'/tmp/foo/a/filename.txt',
'w');
9
UTL_FILE.FCLOSE(l_file_handle);
11
DBMS_OUTPUT.PUT_LINE('FINISHED');
13
end;
15 /
PL/SQL procedure successfully completed.
SQL> show parameter utl_file
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
utl_file_dir string /tmp/foo, /tmp/foo/a
SQL>
also verify the oracle user has r+x on /appl and rwx on /appl/mydir
2 resolution steps for overcoming this error::
1.Be sure that the OS level user has permission to write to a folder
2.Try upper case letters for the directory name i.e. instead of out_dir use OUT_DIR
Out of space may also lead to this issue.
Oracle throws same error if you do not have space on mount point.
ORA-29280: invalid directory path ORA-06512: at "SYS.UTL_FILE", line
41
Please check whether space is available or not on utl_file_dir mountpoint.
For Linux & Solaris use :
df -k ${UTIL_FILE_PATH}
I faced same issue , later got to know it was space issue on mount point.
For the filename put just the name not the path.
So you should put
declare
l_file_handle UTL_FILE.FILE_TYPE;
begin
l_file_handle := UTL_FILE.FOPEN('/appl/mydir',
',filename',
'W');
UTL_FILE.FCLOSE(l_file_handle);
DBMS_OUTPUT.PUT_LINE('FINISHED');
end;
What could cause the following behaviour:
Database 11gR2
declare
l_amt number := dbms_lob.lobmaxsize;
l_dst_loc clob;
l_dst_offset number := 1;
l_lang_ctx number := dbms_lob.default_lang_ctx;
l_src_loc bfile;
l_src_offset number := 1;
l_warning number;
begin
l_src_loc := bfilename('ODS_SERVER_DIRECTORY', '_CIVKD_ASU.CSV');
dbms_lob.createtemporary(l_dst_loc, true);
dbms_lob.fileopen(l_src_loc, dbms_lob.file_readonly);
dbms_lob.loadclobfromfile(l_dst_loc
,l_src_loc
,l_amt
,l_dst_offset
,l_src_offset
,dbms_lob.default_csid
,l_lang_ctx
,l_warning);
commit;
dbms_lob.fileclose(l_src_loc);
dbms_output.put_line(substr(l_dst_loc, 1, 200));
end;
/
ORA-22288: file or LOB operation FILEOPEN failed
.
ORA-06512: in "SYS.DBMS_LOB", line 805
ORA-06512: in line 31
22288. 00000 - "file or LOB operation %s failed\n%s"
*Cause: The operation attempted on the file or LOB failed.
*Action: See the next error message in the error stack for more detailed
information. Also, verify that the file or LOB exists and that
the necessary privileges are set for the specified operation. If
the error still persists, report the error to the DBA.
However opening and reading the exact same file succeeds when using utl_file.
declare
l_file utl_file.file_type;
l_regel varchar2(4000);
begin
l_file := utl_file.fopen('ODS_SERVER_DIRECTORY', '_CIVKD_ASU.CSV', 'R');
-- Haal de volgende regel op
utl_file.get_line(l_file, l_regel);
dbms_output.put_line(l_regel);
utl_file.fclose_all;
end;
So it seems the file is available and accessable by the database.
It's the first time we run into this particular error and it's one of the first 11gR2 instances so maybe there is something 11g specific we don't know about?
=== Update 8-6-2012 ===
Some progress made. It turns out the directory object points to a shared drive. It's a windows server and Oracle runs as Local System. I always thought that it was impossible to read anything from a shared drive in this situation. Apparently in some situations you can using utl_file but not usign dbms_lob.
Could you confirm that ODS_SERVER_DIRECTORY is an actual DIRECTORY
SELECT
*
FROM
dba_objects
WHERE
object_type = 'DIRECTORY'
AND object_name = 'ODS_SERVER_DIRECTORY'
Possibly you have it set in the UTL_FILE_DIR parameter of init.ora (should not be done anymore..)
But its one possibility as to why utl_file would see the directory and dbms_lob would not.