从文件中删除最后一个空行

时间:2017-07-28 06:42:40

标签: oracle utl-file

我有一个从文件中获取数据的代码,文件包含最后一个空/空行,例如,如果一个文件包含4条记录,那么第5行是空白的,我怎么能删除该空行,因为代码执行时由于该空白行,它回滚整个交易并抛出"未找到任何数据" 例外。 以下是我的代码:

calcSum

1 个答案:

答案 0 :(得分:0)

使用utl_file循环浏览文件时,您如何知道自己已到达文件末尾?好吧,抛出no_data_found execption。

所以这就是你的循环结构。

BEGIN
  LOOP
      UTL_FILE.GET_LINE (file, buffer);

      -- evaluate what you've got from the file
      -- and proces it, or not.  In this case we just print it.

      -- Edit: if buffer is empty don't proces it.
      if buffer is not null then
         DBMS_OUTPUT.PUT_LINE(buffer);
      end if;
  END LOOP;

  EXCEPTION  
     --if end of file not action
     WHEN NO_DATA_FOUND 
     THEN 
        NULL;

END;