Read File [message #661337] |
Wed, 15 March 2017 08:13 |
|
Mraouf
Messages: 14 Registered: June 2016 Location: Egypt
|
Junior Member |
|
|
--CREATE or replace DIRECTORY USER_DIR AS 'D:\Reading_File';
CREATE or replace DIRECTORY USER_DIR AS '/ora/oracle/';
GRANT READ ON DIRECTORY USER_DIR TO PUBLIC;
--GRANT read, write ON DIRECTORY USER_DIR TO Public ;
DECLARE
V1 VARCHAR2(200); --32767
F1 UTL_FILE.FILE_TYPE;
BEGIN
F1 := UTL_FILE.FOPEN('USER_DIR','TEST.txt','R');
Loop
BEGIN
UTL_FILE.GET_LINE(F1,V1);
dbms_output.put_line(V1);
EXCEPTION WHEN No_Data_Found THEN EXIT; END;
end loop;
IF UTL_FILE.IS_OPEN(F1) THEN
dbms_output.put_line('File is Open');
end if;
UTL_FILE.FCLOSE(F1);
END;
it gives an error >>
ERROR at line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 449
ORA-29283: invalid file operation
ORA-06512: at line 6
Please help
|
|
|
|
|
|
|
|
|
|
Re: Read File [message #661407 is a reply to message #661337] |
Thu, 16 March 2017 14:23 |
|
mikek
Messages: 29 Registered: January 2017
|
Junior Member |
|
|
Just from Observation of the Post Contents.
I would make sure the file TEST.txt is in the directory specified by the
Create Directory Command:
CREATE OR REPLACE DIRECTORY USER_DIR AS '/ora/oracle/';
The sample output provided indicate that the touch command is creating a
file in the /tmp/ directory and then the procedure is successful.
This leads me to believe that the Create Directory is using the /tmp/ Directory
so the TEST.txt file needs to be in the /tmp/ Directory to work.
Check Oracle Directory Info, use the following SQL:
SELECT * FROM all_directories;
I reformatted/restructured the code for ease of review.
--CREATE OR REPLACE DIRECTORY USER_DIR AS 'D:\Reading_File';
--GRANT read, write ON DIRECTORY USER_DIR TO PUBLIC ;
CREATE OR REPLACE DIRECTORY USER_DIR AS '/ora/oracle/';
GRANT read ON DIRECTORY USER_DIR TO PUBLIC;
DECLARE
v1 VARCHAR2(200); --32767
f1 UTL_FILE.FILE_TYPE;
BEGIN
f1 := UTL_FILE.FOPEN('USER_DIR', 'TEST.txt', 'R');
LOOP
BEGIN
UTL_FILE.GET_LINE(f1, v1);
DBMS_OUTPUT.PUT_LINE(v1);
EXCEPTION
WHEN no_data_found THEN EXIT;
END;
END LOOP;
IF UTL_FILE.IS_OPEN(f1) THEN
DBMS_OUTPUT.Put_line('File is Open');
END IF;
UTL_FILE.FCLOSE(f1);
END;
/
|
|
|