Home > OS >  How to print only the output of dbms_out from a sqlplus script launched from powershell
How to print only the output of dbms_out from a sqlplus script launched from powershell

Time:06-09

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

CodePudding user response:

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.

CodePudding user response:

    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
  • Related