Solved

Save Output of SQL Query in CSV file Using SQL *Plus

Posted on 2011-09-12
7
399 Views
Last Modified: 2012-06-27
Right Now I have done

sql > Spool xyz.txt
sql > <<my Query >>

output in file xyz.txt stored as

Column_Name1               Column_Name2                                                                                                
-------------------------               ---                                                  
ssss66666                             PNR                                                  
sdfgs6666                             PNR                                                  
sfdgfsdg6s                            PNR                                                  
sdfg326sd                             PNR                                                  
sdfg30713                            PNR                                                  
sdfgfsdfg                              PNR                                                  
sdfgsdfgs                             PNR                                                  
sdfgfgfds                             PNR                                                  
G22178                               PNR                                                  
G22402                               PNR                                                  

Column_Name1               Column_Name2                                                  
-------------------------                  ---                                              
sdfgsdfgsdf                              PNR                                                  
sfgfsdgfggf                               PNR                                                  
sdfgsdfgdf                                PNR    


Would like to have the output as a comma seperated values like

column1o/p, column2o/p, column1o/p, column2o/p, column1o/p, column2o/p, column1o/p, column2o/pcolumn1o/p, column2o/p, column1o/p, column2o/pcolumn1o/p, column2o/p, column1o/p, column2o/pcolumn1o/p, column2o/p, column1o/p, column2o/pcolumn1o/p, column2o/p, column1o/p, column2o/pcolumn1o/p, column2o/p, column1o/p, column2o/p............so on//

Please help me with such a query so that I can see the output as CSV file or also into an excel file where the entire value can be given as input to SQL Loader and load into another table in another schema




0
Comment
Question by:XxtremePro
[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
  • 4
  • 3
7 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 36523555
you can use colsep   to  create csv,  but it won't concatenate all the values onto a single line
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 36523589
set colsep ,
select column1, column2 from yourtable
0
 

Author Comment

by:XxtremePro
ID: 36523778
good to have you back...sdstuber...

set echo off newpage 0 space 0 pagesize 0 feed off head off trimspool on
spool distinct_cont_iss.csv
select distinct column1 || ',' || nvl(trim(column2),'PNR')||','
  from contract;
 
spool off

Problem - Column1 defined as char(25 Byte) and data size is only 8 Byte

Giving output of '12345678                 '<< How to avoid the spaces and have output as 12345678,PNR,12345678,PNR,12345678,PNR,12345678,PNR... instead of 12345678                 ,PNR,12345678                 ,PNR,12345678                 ,PNR....

please help...........please

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:XxtremePro
ID: 36523820
I think the space is fine as the new table in which I would load this data has also the same space defined so no constraints

Thanks for your comment...
0
 

Author Comment

by:XxtremePro
ID: 36523829
Would like to know any tools that can help to assist me in loading this new CSV file apart from SQL Loader to load the data as I am not able to find SQL Loader.exe in C:\oracle\product\10.2.0\client_1\BIN

Please help
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 36523896
Oracle's free tool SQL Developer has a data loader

3rd party products PL/SQL Develoer and Toad have data loaders too


if your local client is incomplete, you can reinstall

http://www.oracle.com/technetwork/database/10201winsoft-095341.html
0
 

Author Closing Comment

by:XxtremePro
ID: 36600925
Solutions frm Experts Exchange always help...
0

Featured Post

Industry Leaders: 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

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
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 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 Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

737 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