?
Solved

Appending data in a file by sql* plus spool command

Posted on 2001-07-25
5
Medium Priority
?
2,507 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6320856
SQL> spool empdata
SQL> select * from emp
SQL> select * from dept
SQL> spool Off
0
 

Author Comment

by:dilshad_ch
ID: 6321651
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 15 total points
ID: 6322160
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
ID: 6322832
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
ID: 24554759
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

764 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