Append to spool file Oracle

44,685

Solution 1

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

Solution 2

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

spool d:\lab1.txt append;
Share:
44,685
Sarath Subramanian
Author by

Sarath Subramanian

Updated on March 25, 2020

Comments

  • Sarath Subramanian
    Sarath Subramanian about 4 years

    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.