Solved

Appending data in a file by sql* plus spool command

Posted on 2001-07-25
5
2,049 Views
Last Modified: 2012-05-04
Dear all,
here is the scenario

SQL> spool empdata
SQL> select * from emp
...
...
data displayed from emp table
...
...
SQL>spool off
emp data has been stored in the empdata.lst file.
Now i want to append the same file with the dept table data but by the command

SQL> spool emdata
SQL> select * from dept
...
...
...

it washes all the emp data from file and writes the dept data.

My requirement is to write the dept data from the end of the emp data.

thanx in advance.
Dilshad Ch.
 
0
Comment
Question by:dilshad_ch
5 Comments
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
SQL> spool empdata
SQL> select * from emp
SQL> select * from dept
SQL> spool Off
0
 

Author Comment

by:dilshad_ch
Comment Utility
dear kertzschmar,
the commands you have written does not append data but washes all existing data and then write. i want to append data.

thanks for sparing time
dilshad ch.
0
 
LVL 5

Accepted Solution

by:
ser6398 earned 5 total points
Comment Utility
I don't think there is an append ability in SQL*Plus spool.  As a work-around, you could use your OS to append the files together using the HOST command.

For DOS/Windows, it would look like:

SQL> spool empdata
SQL> select * from emp
...
...
data displayed from emp table
...
...
SQL>spool off
emp data has been stored in the empdata.lst file.
Now i want to append the same file with the dept table data but by the command

SQL> spool temp
SQL> select * from dept
...
...
SQL>spool off


SQL>HOST COPY empdata.sql+temp.sql empdata.sql

0
 
LVL 3

Expert Comment

by:Wadhwa
Comment Utility
create a file x.sql as

set embedded on;
set linesize 65
spool c:\temp\out.lst
select empno,ename from emp;
select deptno,dname from dept;
spool off;

execute the file from sqlplus
sql>@x.sql

 EMPNO ENAME                                                
---------- ----------                                            
      7369 SMITH                                                
      7499 ALLEN                                                
      7521 WARD                                                  
      7566 JONES                                                
      7654 MARTIN                                                
      7698 BLAKE                                                
      7782 CLARK                                                
      7788 SCOTT                                                
      7839 KING                                                  
      7844 TURNER                                                
      7876 ADAMS                                                
      7900 JAMES                                                
      7902 FORD                                                  
      7934 MILLER                                                

14 rows selected.

Elapsed: 00:00:00.60
    DEPTNO DNAME                                                
---------- --------------                                        
        10 ACCOUNTING                                            
        20 RESEARCH                                              
        30 SALES                                                
        40 OPERATIONS                                            

Elapsed: 00:00:00.10
0
 
LVL 7

Expert Comment

by:Mehul Shah
Comment Utility
Not sure why other guys missed it. But below solution works perfectly as spool command does have Append option.

SQL> spool empdata
SQL> select * from emp
...
...
data displayed from emp table
...
...
SQL>spool off
emp data has been stored in the empdata.lst file.

SQL> spool emdata append
SQL> select * from dept
...
...
...

SQL>spool off
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and theā€¦
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to recover a database from a user managed backup

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now