简体   繁体   English

UTL_file:即使遇到空白行也继续读取

[英]UTL_file: continue reading even if it encounters blank rows

I'm new in pl/sql and maybe it is sounds silly,but I have a question. 我是pl / sql的新手,也许听起来很傻,但是我有一个问题。 By Using utl_file,I'm reading a text file. 通过使用utl_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? 知道如何显示所有文件内容,而不仅仅是显示空白吗?

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); 我不知道您对dbms_output.put_line(emptylines);意思是什么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. 也许您可以检查正在处理的行是否不为空并且没有回车符(CHR(13))或换行符(CHR(10)),并以此确定哪些行包含数据,哪些不包含数据。 Hope this help!!!. 希望这个帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM