Solved

SQLPLUS - Format Output to a file.

Posted on 2004-10-01
5
6,556 Views
Last Modified: 2012-05-05
I am new to SQLPLUS and am trying to format my output to a txt file. I am using SPOOL, however there is lot of other information that it spools to the file that I do not need. And also I am not able to make it to a certain column length.

Example; SELECT 'TABLEEMPL      ', FIRST_NM, ID,'*' from mytable.

I want to have just the records on the file and nothing else. In other words my outfile should look like below. My first field has to be always 15 characters, Second be 20 characters, third 10 characters and last 1 character.



TABLEEMPL      JOHN                111       *
TABLEEMPL      CHRISTOPHER   121       *
TABLEEMPL      AL                    131       *



0
Comment
Question by:nazzie303
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:SDutta
ID: 12203551
set PAGESIZE 0
set COLSEP ''
set TERMOUT off
set WRAP on
set VERIFY off
set HEADING off
set SHOWMODE off
set feedback off
col first_nm format a20
col id       format 999999999
spool c:\test.log
SELECT 'TABLEEMPL      ', FIRST_NM, ID,'*' from mytable;
spool off
0
 
LVL 13

Expert Comment

by:riazpk
ID: 12215155
0
 

Author Comment

by:nazzie303
ID: 12217151
Close, but I still get extra text inside the output file.
The Output file  has the extra first line showing the sql and then the last line showinf spool off command too. Besides I get extra spaces afer the '*' in the end of each record.

SQL>SELECT 'TABLEEMPL      ', FIRST_NM, ID,'*' from mytable;
TABLEEMPL      JOHN                111       *      
TABLEEMPL      CHRISTOPHER   121       *      
TABLEEMPL      AL                    131       *      
SQL>Spool Off;

How can I eliminate the sql commands out of the output file.
0
 
LVL 10

Accepted Solution

by:
SDutta earned 125 total points
ID: 12218179
Put the set commands along with the select sql into a file say test.sql

Then from OS

sqlplus /nolog
SQL> connect user/pwd@dbname
Enter password:
Connected.
SQL>@test.sql
SQL>exit

OR

sqlplus user/pwd@dbname @test.sql
0
 

Author Comment

by:nazzie303
ID: 12230480
Great. This is exactly what I was looking for. My output file has everything in order now.
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

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
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…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

760 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

17 Experts available now in Live!

Get 1:1 Help Now