Solved

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

Posted on 2011-09-12
7
401 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
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 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.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

726 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