oracle - 如何假脱机这个 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 查看教程......但我现在迷路了
解决方案
您需要 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;
推荐阅读
- javascript - 使用 Button 移动数据但只有 True Entries
- kubernetes - 作业无效:“选择器”未自动生成
- sql - SQL 输出 Y/N 比较来自不同表的日期列
- ios - MPRemoteCommandCenter playCommand 与 togglePlayPauseCommand?
- dataframe - 使用 UDF 比较和更新两个 DF
- c++ - 如何通过按下 MFC 对话框中的按钮来停止 while 循环
- c# - 将客户端证书传递给 ASP.NET 中的另一个微服务
- stata - 基于另一个观察值的逻辑
- r - 用另一行的值逐列替换特定的 NA
- chart.js - 在使用带有 chart.js 的散点图之前尝试创建我的数据时,背景颜色不起作用