Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append to spool file Oracle

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.

like image 481
Sarath KS Avatar asked Aug 20 '16 07:08

Sarath KS


People also ask

How do I add data to a spooling file?

To create a valid HTML file using SPOOL APPEND commands, you must use PROMPT or a similar command to create the HTML page header and footer. The SPOOL APPEND command does not parse HTML tags. SET SQLPLUSCOMPAT[IBILITY] to 9.2 or earlier to disable the CREATE, APPEND and SAVE parameters.

How do you use the spool command?

Use Spool to Export Query Results to a CSV File table WHERE condition; spool off; In order to execute the Spool, you'll need to run it as a script (for example, if you are using Oracle SQL Developer, you may press F5 to run the Spool as a script). Your CSV file will then get created at your specified path.


1 Answers

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
like image 143
Sarath KS Avatar answered Sep 19 '22 21:09

Sarath KS