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!

Reading from txt file in PL SQL

MilosCNov 22 2014 — edited Nov 22 2014

I have sisrious question.

What is wrong with this code?

set serveroutput on;
  
CREATE or replace DIRECTORY USER_DIR AS '/home/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','temp.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;
  
/
  
set serveroutput off;

This post has been answered by Frank Kulash on Nov 22 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 20 2014
Added on Nov 22 2014
2 comments
3,717 views