How to Append Command Outputs To Oracle SQLPLUS Spool File

advertisements

_____________________________________________________________________________________________________________________

The Eucharistic Miracles of the World
Generally we use sqlplus spool command to record the sql command outputs to a file. It will record the command outputs between spool on and spool off. Generally once you done with the spool off command the output file will be closed from the further logging.

Oracle 10g onwards one more option added to the spool command to append the sql command to an existing file.

Syntax: spool filename append

See an example here.

SQL> spool output.log

SQL> l

  1* select * from tab

SQL> /

 

TNAME                          TABTYPE  CLUSTERID

------------------------------ ------- ----------

BIN$6uc9U2cLQPrgQ55BKAoOFg==$0 TABLE

DEPT                           TABLE

HINT_TEST                      TABLE

MV_DEPT                        TABLE

OBJ_LIST                       TABLE

RUPD$_DEPT                     TABLE

VW_EMP                         VIEW

VW_EMP_DEPT                    VIEW

VW_FORCE_INVALID               VIEW

 

9 rows selected.

 

SQL> spool off

SQL> spool output.log append

SQL> show user

USER is "STHOMAS"

SQL> select * from dept;

 

    DEPTNO DNAME          LOC

---------- -------------- -------------

        10 ACCOUNTING     NEW YORK

        20 RESEARCH       DALLAS

        30 SALES          CHICAGO

        40 OPERATIONS     BOSTON

 

SQL> spool off

 

Printing the content of the file.

SQL> !cat output.log

SQL> l

  1* select * from tab

SQL> /

 

TNAME                          TABTYPE  CLUSTERID

------------------------------ ------- ----------

BIN$6uc9U2cLQPrgQ55BKAoOFg==$0 TABLE

DEPT                           TABLE

HINT_TEST                      TABLE

MV_DEPT                        TABLE

OBJ_LIST                       TABLE

RUPD$_DEPT                     TABLE

VW_EMP                         VIEW

VW_EMP_DEPT                    VIEW

VW_FORCE_INVALID               VIEW

 

9 rows selected.

 

SQL> spool off

SQL> show user

USER is "STHOMAS"

SQL> select * from dept;

 

    DEPTNO DNAME          LOC

---------- -------------- -------------

        10 ACCOUNTING     NEW YORK

        20 RESEARCH       DALLAS

        30 SALES          CHICAGO

        40 OPERATIONS     BOSTON

 

SQL> spool off

_____________________________________________________________________________________________________________________

Website Stats

0 comments:

Post a Comment

Labels

Oracle (629) Script (86) General (77) Unix (47) Blog (23) Technology (19) gadget (6) games (6) Business (3) OCI (3) SQL* Loader (3) Datapump (2)
 

acehints.com Copyright 2011-23 All Rights Reserved | Site Map | Contact | Disclaimer