Solved

SQLPLUS - Format Output to a file.

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  â€¦
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
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.
Suggested Courses

628 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