8

I have one script file called Test.sql in D:\Scripts folder and the content of the file is given below

SET SERVEROUTPUT ON
SET DEFINE OFF
SPOOL Test.log;


SELECT USER_NAME FROM TUP_USER WHERE USER_ID=1432;


SPOOL OFF;
SET DEFINE ON
SET SERVEROUTPUT OFF

I normally execute this by opening command prompt, locate to D:\Scripts and give sqlplus username/password@Database and then give @test.sql to execute this and it will generate a log file called Test.log

Every time I execute this, it replaces the old file with the new data. I need to append new data to the file using spool. Is there a way to do that?

Any help would be appreciated. Thanks in advance.

Sarath Subramanian
  • 20,027
  • 11
  • 82
  • 86
  • Did you look at [the SQL\*Plus documentation](http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve043.htm#SQPUG126)? – Alex Poole Aug 20 '16 at 09:48

2 Answers2

25

Finally got the solution for this!

Add append after Test.log

SET SERVEROUTPUT ON
SET DEFINE OFF
SPOOL Test.log append;


SELECT USER_NAME FROM TUP_USER WHERE USER_ID=1432;


SPOOL OFF;
SET DEFINE ON
SET SERVEROUTPUT OFF
Sarath Subramanian
  • 20,027
  • 11
  • 82
  • 86
2

Just add append when you're writing the spool query:

spool d:\lab1.txt append;
Zoe
  • 27,060
  • 21
  • 118
  • 148
shouzeb hasan
  • 21
  • 1
  • 2