首页 > 解决方案 > 如何假脱机这个 pl/SQL 过程的结果

问题描述

是的,我知道并且我也读过它是不可能假脱机的 pl/sql prozedure 并且那个人应该使用 utl_file 但实际上,我不知道它是如何工作的。有人可以帮助或只是说明我如何在这里做到这一点。

这就是我的代码,我有一个游标,我想假脱机这个游标的结果,你可以在 dbms_output 中看到。

set serveroutput on
clear screen;

spool C:\Users\p.k\Documents\text.txt

declare
    l_output   utl_file.file_type;
    cursor cp_username (p_v_username in varchar2)
    is
       select owner, table_name          
       from   all_tables
       where owner = p_v_username
       order by owner, table_name ;   
begin
     l_output := utl_file.fopen();
     dbms_output.put_line('Alle Tabellen der User: &g_username');
     for cp_kur in cp_username('&g_username') loop
         dbms_output.put_line('Tabelle: '|| cp_kur.table_name );
     end loop;
end;

spool off;

我首先开始使用假脱机,但他已经创建了文件并将输出与错误一起放入,然后我开始使用 utl_file 查看教程......但我现在迷路了

标签: oracleplsql

解决方案


您需要 utl_file.put按如下方式使用:

declare
    l_output   utl_file.file_type; 
begin
     l_output := utl_file.fopen(
                  'utl_dir' -- File location
                , 'test_file.txt' -- File name
                , 'w' -- Open mode: w = write.
                    );
     utl_file.put(l_output,'Alle Tabellen der User: &g_username');
     for cp_kur in (select owner, table_name          
       from   all_tables
       where owner = '&g_username'
       order by owner, table_name) loop
         utl_file.put(l_output, 'Tabelle: '|| cp_kur.table_name );
     end loop;
     utl_file.fclose(l_output);
end;

推荐阅读