Search code examples
oracle-databaseshellsqlplus

Add log to log file from external .sql executed in sqlplus


I have a test.sh script with following code:

LOG=output.log

sqlplus -s user/pwd@db << EOF > ${LOG}
    WHENEVER OSERROR EXIT 9;
    WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK;

    @testsqlfile
EOF

and testsqlfile.sql file:

SET SERVEROUTPUT ON

EXEC DBMS_OUTPUT.PUT_LINE('TEST');

I can't get the log printed in testsqlfile.sql to be added in output.log file.

If i add SET serveroutput and EXEC DBMS_OUTPUT.PUT_LINE('TEST'); directly in test.sh script it works fine. But i can´t add it to output.log file from external testsqlfile.sql executed as described.

As far as I could find it should work, but it does not.

Thanks.


Solution

  • I just executed this SQL script directly inside my bash.

    sqlplus -s user/pwd@db << EOF > ${LOG}
    WHENEVER OSERROR EXIT 9;
    WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK;
    
    Direct query
    EOF