Invalid file operation in pl/sql - oracle

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.

Related

ORA-29283: invalid file operation when calling utl_file.fopen on Windows server 2016

Most of the answers I've seen are for Linux. Windows permissions have an element of black magic about them. This is Windows Server 2016.
I created the d:\data\transfer\sirius\ directory on the Oracle database server.
As SYSDBA I do the following:
create or replace directory SIRIUS_DIR as 'd:\data\transfer\sirius\';
grant read,write on directory SIRIUS_DIR to SIRIUS;
Then on another server, in a SQL*Plus session as the SIRIUS user, I run:
DECLARE myFile utl_file.file_type;
BEGIN
myFile := utl_file.fopen('SIRIUS_DIR ', 'random.txt', 'w', 32000);
END;
/
Which gives:
ERROR at line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 41
ORA-06512: at "SYS.UTL_FILE", line 478
ORA-06512: at line 3
How to proceed?
Figured it out. You need to grant full access to the ORA_INSTALL group to the directory in question on the database. According to the Oracle configuration docs:
The ORA_INSTALL group contains all the Oracle Home Users for all
Oracle homes on the server.
Thanks to this kindly blogger for his solution.

Oracle DATAPUMP import failed

I am currently trying to import a database using DBMS_DATAPUMP in PL/SQL using the following script.
DECLARE
h1 NUMBER;
BEGIN
h1 := DBMS_DATAPUMP.OPEN('IMPORT', 'FULL', NULL, DBMS_SCHEDULER.generate_job_name, 'LATEST');
DBMS_DATAPUMP.ADD_FILE(handle => h1, filename => 'EXAMPLE6.DMP', directory => 'DUMP');
DBMS_DATAPUMP.START_JOB(h1);
dbms_datapump.detach(h1);
END;
/
Everytime I execute this code, I get the following error message.
ERROR in line 1:
ORA-39001: invalid argument value
ORA-06512: in "SYS.DBMS_SYS_ERROR", line 79
ORA-06512: in "SYS.DBMS_DATAPUMP", line 4929
ORA-06512: in "SYS.DBMS_DATAPUMP", line 5180
ORA-06512: in line 5
I already googled the error, but the answer mostly consisted of checking if the directory was already created and if the user had read and write access to the directory.
I also tried the impdp tool just as an experiment, to see if I could execute imports that way.
impdp pdb2 directory="DUMP" dumpfile="EXAMPLE6.DMP"
Based on the user I am executing impdp as, I get different error messages.
As a user with all privileges granted:
ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-39155: error expanding dump file name "C:\Users\...\EXAMPLE6.DMP"
ORA-48128: opening of a symbolic link is disallowed
As the sysdba user:
ORA-39002: invalid operation
ORA-39070: unable to open the log file
ORA-39087: directory name DUMP is invalid
As I already said, the directory does exist on my drive, I created the directory called DUMP in Oracle and granted read and write access to my user.
All help would be appreciated and I would be happy to clarify if I wrote something confusing!
Edit:
Output of select directory_name, directory_path from dba_directories;
DIRECTORY_NAME
--------------------------------------------------------------------------------
DIRECTORY_PATH
--------------------------------------------------------------------------------
DUMP
C:\Users\Nemanja\Desktop\oraclePLS
I forgot to mention, that the Oracle service has complete access to the specified Windows directory.

FOPEN not accepting directory path

I'm having trouble with the line
F := UTL_FILE.FOPEN('my_directory', 'MyCSV.csv', 'R');
After previously running
CREATE DIRECTORY my_directory AS 'C:\Users\timfo\eclipse-workspace\CSVCreation';
which succeeds. The error I'm getting is
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 9
29280. 00000 - "invalid directory path"
*Cause: A corresponding directory object does not exist.
*Action: Correct the directory object parameter, or create a corresponding
directory object with the CREATE DIRECTORY command.
but I've made sure that the user has permission with
grant create any directory to TimGraupner2;
CREATE DIRECTORY my_directory AS 'C:\Users\timfo\eclipse-workspace\CSVCreation';
grant read on directory my_directory to TimGraupner2;
and all those succeeded. I've tried entering the full directory path in the FOPEN line, and that didn't work either. What's going on?

Cannot write file xml output form a procedure - ORA-06512: a "SYS.UTL_FILE"

in our production environment we use a procedure that read from our DB Oracle 12c and write about 2000 files xml in output on the filesystem, all in the same directory.
Now we have a problem: after that 1400 files are already writed, the procedure fails with error:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
There is enough space on the filesystem to write the files and i have already checked the permissions.
In the procedure we call:
xdb.dbms_xslprocessor.clob2file(xml_document,R_FILE_FOLDER,substr(xml_file_name,0,instr(xml_file_name,'.',-1)-1)||'.unc',nls_charset_id('AL32UTF8'));
Thank you

Open a remote file using utl_file.fopen on Windows

I have to access a remote file in a different computer using utl_file.
This is what I did:
create a user with Adminstrator+Users+ora_db profile in the remote PC, the same user is created with the same role in my PC.
Run the Oracle Services using this administrator account
Map the remote directory under Windows
use the following command to configure and accesss the file:
create or replace directory REMOTE_LOG as '\\remote_shared_dir\log';
declare
f UTL_FILE.FILE_TYPE;
line VARCHAR2(32767) ;
begin
BEGIN
f := UTL_FILE.FOPEN('REMOTE_LOG','toto.txt','R',32764);
EXCEPTION WHEN OTHERS THEN
dbms_output.put_line('err '||sqlerrm);
END;
UTL_FILE.GET_LINE( f, line );
UTL_FILE.FCLOSE( f ) ;
end;
But it failed with:
[Error] Execution (7: 3): ORA-29282: invalid file ID
ORA-06512: at "SYS.UTL_FILE", line 735
ORA-06512: at line 13
When I remove the exception handler I instead see:
[Error] Execution (7: 3): ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 8
What am I doing wrong?

Resources