Solved

SQLPLUS - Format Output to a file.

Posted on 2004-10-01
5
6,589 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
[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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
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.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
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…

763 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