UTL_file: continue reading even if it encounters blank rows

836 views Asked by At

I'm new in pl/sql and maybe it is sounds silly,but I have a question. By Using utl_file,I'm reading a text file. But my text file contains blank spaces between rows, and I need to continue to read all content even after that blank space. below I displayed my code that I used, and the template of my text file.

DECLARE 
        V1 VARCHAR2(200); 
        F1 UTL_FILE.FILE_TYPE;
     BEGIN 

        F1 := UTL_FILE.FOPEN('directory','text.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;
        dbms_output.put_line(emptylines);

        UTL_FILE.FCLOSE(F1); 
     END; 
     /

Template of my text file

alarma2
alarma2
alarma2


alarma3
alarma3
alarma3
alarma3

Any idea how I can make to display all file content, not just until blank space?

1

There are 1 answers

0
Leonardo Heis On BEST ANSWER

Maybe you could try this:

...
    Loop
    BEGIN
       UTL_FILE.GET_LINE(F1,V1); 
       IF  (TRIM(V1) is not null) AND ((TRIM(V1) <> CHR(10)) OR (TRIM(V1) <> CHR(13)))  THEN
                  dbms_output.put_line(V1);
       END IF;
...

I don't know what you mean with dbms_output.put_line(emptylines); so I didn't care a bout it :). Maybe you could check if the line you are processing is not empty and hasn't a carriage return (CHR(13)) or line feed (CHR(10)) and with this you could determinate which lines contain data and which not. Hope this help!!!.