SQL> CREATE DIRECTORY attdata AS 'c:\attdata'; Directory created. SQL> GRANT read, write ON DIRECTORY attdata TO PUBLIC; Grant succeeded. DECLARE f UTL_FILE.file_type; s VARCHAR2(2000); BEGIN f := UTL_FILE.fopen('ATTDATA','prtext.txt','R'); LOOP BEGIN UTL_FILE.get_line(f,s); DBMS_OUTPUT.PUT_LINE(s); exception when no_data_found then --dbms_output.put_line('file is done, so no data found'); exit; end; end loop; UTL_FILE.fclose(f); END; / 111 abc 222 xxx 333 zzz PL/SQL procedure successfully completed. SQL>
Either you are using different directory object or file does not exits in your directory object, because when I am able to view the file (as I showed above), you should too be able to run the code. Also check the OS user which is currently logged into sqlplus or calling PL/SQL object, having correct permission to access the folder and file.
SQL>host dir c:\attdata\prtext.txt <--- The folder should name be same as you said when you create directory ... command and the file which you are going to open.