How to echo text during SQL script execution in SQLPLUS

glenneroo picture glenneroo · Nov 7, 2013 · Viewed 140.7k times · Source

I have a batch file which runs a SQL script in sqlplus and sends the output to a log file:

sqlplus user/pw < RowCount.sql > RowCount.log

My log file contains this:

Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production

SQL> SQL> 
  COUNT(*)
----------
     0

SQL> 
  COUNT(*)
----------
     0

etc. but it's several thousand lines of output and therefore hard to determine which results belong to which statement.

I would like to add some formatting to the output, so that I may discern what happened. Either an echo of the executed statement or manually inserting some "echo" statements into the script would be fine. Ideally it would look something like this:

SQL> select(*) from TableA;
  COUNT(*)
----------
     0

SQL> select(*) from TableB;
  COUNT(*)
----------
     0

Answer

glenneroo picture glenneroo · Nov 8, 2013

The prompt command will echo text to the output:

prompt A useful comment.
select(*) from TableA;

Will be displayed as:

SQL> A useful comment.
SQL> 
  COUNT(*)
----------
     0