Solved

SQLPLUS - Format Output to a file.

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Oracle Insert not working 10 30
Read XML values 8 41
oracle forms question 22 39
Error in creating a view. 8 19
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
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…
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 explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

808 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