9

Is there a way where sqlplus can print what statement it executed. I mean I have some .sql files that I run in a bash script. I need to know when I read the log file which statement sqlplus ran.

Example: Say I have this test.sql file:

set timing on
create table foo (a varchar2(10));
create table bar (b varchar2(10));
exit

When I check the log I get this:

Table created.

Elapsed: 00:00:00.02

Table created.

Elapsed: 00:00:00.01

Which is not informative. Is there a way where I can get output like this:

Table foo created.

Elapsed: 00:00:00.02

Table bar created.

Elapsed: 00:00:00.01

Or even like this:

create table foo (a varchar2(10));

Table created.

Elapsed: 00:00:00.02

create table bar (b varchar2(10));

Table created.

Elapsed: 00:00:00.01

I know I can use PROMPT before each statement but I have big sql scripts and it would be tedious to write PROMPT before each statement.

EDIT:

For Allan's solution to always work (i.e. using "set echo on"), you should avoid the following:

1) Don't use the -S option with sqlplus because this will suppress the display of echoing of commands.

2) Don't "cat" your script to sqlplus like this:

cat test.sql | sqlplus scott/tiger@orcl

2 Answers 2

20

The command you're looking for is SET ECHO ON, which will repeat the each statement that is issued.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. This worked by avoiding two things. See my updated question.
This doesn't work when running @script.sql. In that case, the commands within the script get echoed, but the original command (@script.sql) doesn't get echoed. For tracability purposes, I really need the user commands to be logged.
(in all other cases though, set echo on works great)
This still isn't working with my here document. Is that problematic like cat?
-3

If you need to know the exact creation time for the objects you could query DBA_OBJECTS or ALL_OBJECTS for the CREATED column.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.