如何仅从powershell启动的sqlplus脚本中仅打印dbms_out的输出

发布于 2025-02-05 21:15:02 字数 566 浏览 2 评论 0原文

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
  1. SQL*Plus版本.......总是在开始时打印出来。我不要。
  2. 我的查询线打印。没关系。
  3. 断开连接....从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
  1. SQL*Plus Version..........is always printed in the beginning. I don't want it.
  2. the lines of my query are printed. that is OK.
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

時窥 2025-02-12 21:15:03

您只需使用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 options SET FEEDBACK OFF, SET HEAD OFF and SET 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.

柠檬 2025-02-12 21:15:03
    set serveroutput on
    set feedback off
    set heading off
    set echo off

    DECLARE
        CURSOR c1 IS
            select 2 as object_text  from dual;
    BEGIN
        FOR i IN c1
        LOOP
            DBMS_OUTPUT.put_line (i.object_text );
        END LOOP;
    END;
    /
    EXIT;


    PS C:\otr> sqlplus -s user/password@dev19  @c:\otr\file1.sql  -S | Out-String | echo
    2
    set serveroutput on
    set feedback off
    set heading off
    set echo off

    DECLARE
        CURSOR c1 IS
            select 2 as object_text  from dual;
    BEGIN
        FOR i IN c1
        LOOP
            DBMS_OUTPUT.put_line (i.object_text );
        END LOOP;
    END;
    /
    EXIT;


    PS C:\otr> sqlplus -s user/password@dev19  @c:\otr\file1.sql  -S | Out-String | echo
    2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文