Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

read&write server files from plsql code

Gor_MahiaOct 22 2021

All,
i am having the below anonymous block to READ and WRITE to a file located on the server location mapped to the directory object as below,
DIRECTORY_NAME : DIRECTORY_PATH
MY_DIR : \\QRD_ATT\Consumer_Projects\commonfiles\portal

grants exists as below,
GRANTEE TABLE_SCHEMA TABLE_NAME PRIVILEGE GRANTABLE
=========================================================
APTS SYS MY_DIR EXECUTE YES
APTS SYS MY_DIR READ YES
APTS SYS MY_DIR WRITE YES

I am running this code from APTS shema
DECLARE
F UTL_FILE.FILE_TYPE;
CURSOR C1 IS select EMPNO, ENAME, SAL from emp where rownum <= 10 ;
C1_R C1%ROWTYPE;
BEGIN
F := UTL_FILE.FOPEN('MY_DIR','txt1.txt','w',32767);
FOR C1_R IN C1
LOOP
UTL_FILE.PUT(F,C1_R.EMPNO);
UTL_FILE.PUT(F,','||C1_R.ENAME);
UTL_FILE.PUT(F,','||C1_R.SAL);
UTL_FILE.NEW_LINE(F);
END LOOP;
UTL_FILE.FCLOSE(F);
END;

but iam getting the below error yet I've full read & write access to the location ?
Error report -
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 6
29283. 00000 - "invalid file operation%s"
*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.

Any help why iam getting this error?

thanks.

Comments

Frank Kulash
Answer

Hi, @francy77
In schema1 i granted
grant insert,update, delete on t_table_var to ico
Grant the SELECT privilege, as well as INSERT, UPDATE and DELETE.
It sounds like ico has the SELECT privilege only via a role. Roles don't count in AUTHID OWNER stored procedures; all the necessary privileges must be granted directly to the user, or to PUBLIC.
Also, does ico have the CREATE PROCEDURE system privilege?
EDIT: After reading @paulzip 's reply (below) I added AUTHID OWNER above.

Marked as Answer by francy77 · Feb 2 2021
Paulzip

You need the select privilege too,
Also, another thing to bear in mind, is the procedure defined with definer rights (permissions are based on who owns the procedure) or invoker rights (permissions are based on who is calling the procedure)?
The default is definer rights.
Example of invoker rights....

create or replace procedure update_par(pcod in varchar2) authid current_user is 
francy77

I don t know why but granting select was enought, as your suggestion there was a missing SELECT in the grant instruction, so I added it and it works;
The strange thing is that indeed without the select even the delete dos't worked;

1 - 3

Post Details

Added on Oct 22 2021
11 comments
994 views