Creating CSV files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating CSV files
# 8  
Old 04-21-2010
The SQL file is in the server and used by many downstreams.
its simple like "select col1,col2,col3.....from ...where...."
basically we used to call the sql and see the output trough a DB likn.
now the requirement is to save the o/p in a csv file.
in the unix box we can only call that sql file
I have no idea how to store the data returned by that sql in CSv format.

---------- Post updated at 02:58 PM ---------- Previous update was at 02:56 PM ----------

PFB the query (partial)

Code:
SELECT Distinct 'Success' As CallStatus, 
to_char (( (decode(J.ACCT_SESSION_TIME, 5,6, 4,6, 3,6, 2,6, 1,6, J.ACCT_SESSION_TIME)))) As CallDuration,  
( INITCAP(O.CUSTOMER_NAME) ) As Customer,  ( (C.countryname) ) As CallingSiteCountry,  
( INITCAP(A.CITY) ) As CallingSite,  
( Decode(AA.hostindicator,'ims',G.COUNTRYNAME,CC.COUNTRYNAME) ) As CalledCountry,  
( (Decode(AA.hostindicator,'ims','2','1')||Decode(length(J.MOBILEPREFIX),null,'0','1') ) ) As CallTypeSort, 
To_Char ((J.POSTDIALDELAY)) As PostDialDelay, J.TIMESTAMP as CalledTime
FROM ACCOUNTSALTR A, VOFR_JOURNAL J, VOFR_COUNTRY C, VOFR_COUNTRY CC,
VOF000.VOFR_ACCOUNTSALTR AA, VOF001.ODSCUSTINFO O, VOF000.VOFR_DNIS D, VOF000.VOFR_GMSRATES G 
WHERE A.IPADDRESS = J.ORIG_IP AND AA.IPADDRESS = J.DEST_IP AND A.ACCOUNTNO = O.BILLING_ACCOUNT_NUMBER 
AND D.PHONEPREFIX = G.PHONEPREFIX (+)  AND D.CALLED_STATION_ID (+) = J.CALLED_STATION_ID 
AND J.ACCT_SESSION_TIME > 0


Last edited by Scott; 04-21-2010 at 06:34 AM.. Reason: Please use code tags
# 9  
Old 04-21-2010
Maybe download a copy of Oracle SQL Developer?

---------- Post updated at 10:30 AM ---------- Previous update was at 10:25 AM ----------

Or if you have to use sqlplus from the command line...
Code:
$ sqlplus user/pass
SQL*Plus:...
:
SQL> set markup html preformat on
SQL> set colsep ','
SQL> set linesize 32000 trims on
SQL> set pagesize 0
SQL> spool tmpfile.csv
SQL> start script.sql
:
SQL> spool off
SQL> exit
Disconnected from Oracle Database...

$ sed -e 's/ *,/,/g' tmpfile.csv > outfile.csv

# 10  
Old 04-22-2010
thanks ygor,

I am trying this option.
# 11  
Old 04-28-2010
Hello,

The problem has been solved..
thanks ygor.
now i can create the CSV file but while running the SH from where i am calling the SQL.
the output is comming in display.
How to get rid of it?

FYI-- serveroutput is off

---------- Post updated at 07:18 PM ---------- Previous update was at 06:50 PM ----------

term off; got it..
thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match columns from two csv files and update field in one of the csv file

Hi, I have a file of csv data, which looks like this: file1: 1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628 2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Discussion started by: djoseph
10 Replies

2. UNIX for Dummies Questions & Answers

Creating a csv file with header in UNIX

I have a flat file that contains dynamic list of variables like a=1 b=2 c=3 . .. z=26 I need to convert the above into a csv file having the format below: a,b,c,..,z 1,2,3,..,26 Please note, I do not want a comma separating the last variable. I tried to refer the post... (4 Replies)
Discussion started by: vkumbhakarna
4 Replies

3. UNIX for Dummies Questions & Answers

Problem in creating CSV file

Hi guys, I am not experienced with Unix, so please dont mind if the question seem to be irrelevant. I have written a simple script, that connects DB & fetches few records from a table. I wanted to get those details as file in .CSV format via mail. -I stored the query o/p in a file. -I... (6 Replies)
Discussion started by: sumitburnwal88
6 Replies

4. Shell Programming and Scripting

creating a csv file from this 1 liner?

I'm trying to create a csv file by running awk and sed on a number of xml files in a directory; I'm using this below: hostname; grep "BuildDate" /dir/ABCD/configuration/*/*.xml | awk -F"/" '{ print $5 }' > /tmp/tempfile.txt; grep "BuildDate" /dir/ABCD/configuration/*/*.xml | awk -F\" '{ print $2... (2 Replies)
Discussion started by: rich@ardz
2 Replies

5. UNIX for Dummies Questions & Answers

Creating a report from csv file.

Hi Gurus, I need your help in transforming the CSV file into some what a report format. My source file looks like below Date,ProdID,TimeID,LevelID 2010-08-31,200,M,1 2010-08-31,201,Q,2 2010-08-31,202,Y,1 2010-08-31,203,M,5 Output required is ... (9 Replies)
Discussion started by: naveen.kuppili
9 Replies

6. UNIX for Dummies Questions & Answers

creating a CSV file for past 7 days

I have a requirement which will select the files with a specific naming convention which got created in past 7 days in a specific directory.Lets say the directory is /data/XYZ and the file names follow the below nomenclature like Daily_File*.txt I just need to create one CSV file which will... (12 Replies)
Discussion started by: dr46014
12 Replies

7. UNIX for Dummies Questions & Answers

Creating CSV Files

I have a requiremnt to create one CSV file with initial 5 lines as blank rows. From 5th row onwards the file is to be created from a list of varibales which gets evaluated. Say A,B,C,D,E are 5 varibales with some value associated with each of them and data type is string. So the 6th row should... (1 Reply)
Discussion started by: dr46014
1 Replies

8. UNIX for Advanced & Expert Users

Creating multiple worksheets in CSV file

Hello, I've been tasked with sending 3 types of data (file size, row count, and file name) to a csv file every month for various vendors. I have been asked to put this in one csv or xls file with each vendor being a different tab (or worksheet). Until now, we have been finding and emailing... (4 Replies)
Discussion started by: tekster757
4 Replies

9. Shell Programming and Scripting

creating a csv file in awk

Hi All I am trying to create a csv file in the korn shell and the script segment is as follows: if then # NEED TO ADD INFO TO THE EMAIL FILE ABOUT THE DRIVE THAT'S FILLING UP echo "$drive $percent% $space "|\ awk '{printf("%d/t"|"%d/t"|"%d/t\n",... (6 Replies)
Discussion started by: Segwar
6 Replies

10. Shell Programming and Scripting

help!!!!!! in creating csv report

Dear All, I need the help of all the genius minds to find solution to my problem. This problem has left me in a situation like I am in middle of sea with a rubber boat , so please help me out to get out of this. Problem:-- I m using the informix database with installed on linux machine and... (6 Replies)
Discussion started by: xander
6 Replies
Login or Register to Ask a Question