使用 TEXT_IO 显示一条记录的过程

Procedure showing one record using TEXT_IO

我在 oracle forms 11g 中有程序,其中 select 记录并写入文本文件。我通过执行 select 语句有 780 条记录,但在文本文件中只显示一条记录

代码:

PROCEDURE list_files IS
out_file text_io.file_type;
v_name_of_files VARCHAR2(500);
BEGIN
  for c in
  (
    select filename from tab1 
    WHERE filename NOT IN (select distinct filename from tab2)
    order by filename
)
loop
    v_name_of_files := c.filename;
end loop;

out_file := text_io.fopen('C:log.txt', 'w');

text_io.put_line(out_file,'List of files uploaded failed : ');

TEXT_IO.new_line(out_file);

text_io.put_line(out_file,v_name_of_files);

text_io.fclose(out_file);

END;

我正在使用 oracle 数据库 11g 谢谢

所以你想输出780个失败文件的名字?目前您的代码正在执行一个循环,该循环覆盖 v_name_of_files 779 次,然后输出 tab1 的最后一个条目。您需要更改循环,以便它调用文件输出。

PROCEDURE list_files IS

  out_file text_io.file_type;

BEGIN

  out_file := text_io.fopen('C:log.txt', 'w');

  text_io.put_line(out_file,'List of files uploaded failed : ');

  for c in
  (
    select filename from tab1 
    WHERE filename NOT IN (select distinct filename from tab2)
    order by filename
  )
  loop
     text_io.put_line(out_file,c.filename);  
  end loop;

  text_io.fclose(out_file);

END;