Solved

Appending data in a file by sql* plus spool command

Posted on 2001-07-25
5
2,336 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 5 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious sideā€¦
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
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.

738 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