如何仅从powershell启动的sqlplus脚本中仅打印dbms_out的输出
myScript.sql:
set serveroutput on
set feedback off
set heading off
set echo off
DECLARE
CURSOR c1 IS
select 2 from dual
BEGIN
FOR i IN c1
LOOP
DBMS_OUTPUT.put_line (i.object_text );
END LOOP;
END;
/
exit;
我以此为脚本:
sqlplus user/pass@database @Dpath\myscript.sql -S | Out-String | echo
- SQL*Plus版本.......总是在开始时打印出来。我不要。
- 我的查询线打印。没关系。
- 断开连接....从Oracle数据库中总是打印出来。我不希望它
这个代码只是一个可生殖的例子。我知道,对于特定情况,还有其他方法可以做到这一点。但是我想要的是只打印DBMS_OUT
myscript.sql:
set serveroutput on
set feedback off
set heading off
set echo off
DECLARE
CURSOR c1 IS
select 2 from dual
BEGIN
FOR i IN c1
LOOP
DBMS_OUTPUT.put_line (i.object_text );
END LOOP;
END;
/
exit;
I call my script with that:
sqlplus user/pass@database @Dpath\myscript.sql -S | Out-String | echo
- SQL*Plus Version..........is always printed in the beginning. I don't want it.
- the lines of my query are printed. that is OK.
- Disconnected .... from Oracle Database is always printeed in the end. I don't want it
This code is just a reproductible example.I know that for the particular case, there is other way to do that. But what I want is to print just the dbms_out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需使用
spool
来创建一个单独的文件,您将在其中完全控制所打印内容。您还可以使用选项的组合设置反馈
,设置头
和设置验证
以删除接收到的行数,列名称等,使您的文件看起来更像是实际报告,而不是重定向的输出。You can just use
SPOOL
to create a separate file, where you will have full control of what is printed. You can also use a combination of the optionsSET FEEDBACK OFF
,SET HEAD OFF
andSET VERIFY OFF
to remove the number of rows received, column names etc. so that your file looks more like an actual report instead of redirected output.