The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
UNIX - File/Table/Data manipulation pc2001 UNIX for Dummies Questions & Answers 2 09-21-2009 05:09 PM
load a data from text file into a oracle table raji35 Shell Programming and Scripting 2 01-15-2009 03:48 AM
unix file to oracle table ran16 Shell Programming and Scripting 2 06-14-2008 03:27 PM
unix script for update or insert records from a file to a oracle table unihp1 UNIX for Advanced & Expert Users 1 06-11-2008 04:21 AM
unix script to export data from csv file to oracle database vinayagan Shell Programming and Scripting 3 07-20-2005 05:16 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
aemunathan aemunathan is offline
Registered User
  
 

Join Date: May 2008
Posts: 76
select data from oracle table and save the output as csv file or .txt file in unix/solaris - script

Hi

I need to execute a select statement in a solaris environment with oracle database. The select statement returns number of rows of data. I need to execute the query every five minutes and store the output to a file named as the timestamp at that time like 20091105001415.txt or csv (yyyymmddhh(24hr format)miss)

i thought of a making script and put it in the cron ...
I dont want the headers for the query output and the column values needs to be comma separated or tab separated
and i just tried this way......

Code:
#!/bin/bash
export ORACLE_HOME=/u01/app/oracle/product/9.2.0
export PATH=$PATH:$ORACLE_HOME/bin
sqlplus -s username/password@schema<<!
Spool on
set heading off
Spool /aaa/ss.txt
SELECT MU.MSISDN,TA.X, TA.Y, TA.STREET || ' ' || TA.DISTRICT || ' ' || TA.CITY || ' ' || TA.STATE || ' ' || TA.COUNTRY || ' ' || TA.
ZIP AS ADDRESS, TA.TIME_STAMP FROM TEAM_ACTIVITY TA, MOBILE_UNIT MU WHERE TO_TIMESTAMP(TO_CHAR(MSG_DATE_INFO,'DD-MON-YYYY HH24:MI:SS
'), 'DD-MON-YYYY HH24:MI:SS') > TO_TIMESTAMP(TO_CHAR(SYSDATE-INTERVAL '05' MINUTE, 'dd/mon/YYYY HH24:MI:SS'),'DD-MON-YYYY HH24:MI:SS
') AND TEAM_ID in (select team_id from team where mobile_unit1 in (select mu_id from mobile_unit where com_id='473' ) ) AND TA.MOBIL
E_UNIT1=MU.MU_ID;
Spool off
!

and the output is not the way i wanted...
Quote:
9090900819 70.2545924 3.0725022
Institute of Child Health & Hospital Hallis Road Chennai Tamil Nadu Indi
a
04-NOV-09

9090900719 70.2545924 3.0725022
Institute of Child Health & Hospital Hallis Road Chennai Tamil Nadu Indi
a
04-NOV-09
i need the output in a single line like this and the time stamp should have the actual values including hour minute and seconds in the query result(it comes if i execute the query in sql editor) . data has to be redirected the file created with the time stamp.
Quote:
9090900819,70.2545924,3.0725022,Institute of Child Health & Hospital Hallis Road Chennai Tamil Nadu India,04-NOV-09 23:29:33
9090900719,70.2545924,3.0725022,Institute of Child Health & Hospital Hallis Road Chennai Tamil Nadu India,04-NOV-09 23:26:33
  #2 (permalink)  
Old 4 Weeks Ago
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,134
Perhaps you could add

Code:
set wrap off
set colsep ,

and maybe also set the linesize.

Last edited by scottn; 4 Weeks Ago at 03:24 PM.. Reason: oh yes, and set feedback off!
  #3 (permalink)  
Old 4 Weeks Ago
SFNYC SFNYC is offline
Registered User
  
 

Join Date: Jun 2008
Location: New York City
Posts: 95
You have to select all your columns as one big string, concatenating each column:


Code:
SELECT MU.MSISDN,TA.X, TA.Y, TA.STREET || ' ' || TA.DISTRICT || ' ' || TA.CITY || ' ' || TA.STATE || ' ' || TA.COUNTRY || ' ' || TA. ZIP AS ADDRESS, TA.TIME_STAMP

Should be


Code:
SELECT MU.MSISDN || ',' || TA.X || ',' || TA.Y || ',' || TA.STREET || ' ' || TA.DISTRICT || ' ' || TA.CITY || ' ' || TA.STATE || ' ' || TA.COUNTRY || ' ' || TA. ZIP || ',' || TIME_STAMP

  #4 (permalink)  
Old 4 Weeks Ago
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,134
That's probably easier ;-)

Last edited by scottn; 4 Weeks Ago at 05:36 PM..
  #5 (permalink)  
Old 4 Weeks Ago
aemunathan aemunathan is offline
Registered User
  
 

Join Date: May 2008
Posts: 76
hi,
its coming but am having a newline between each record that i dont require...needs to be removed....and at the end of the records am getting 10 rows selected, this also needs to removed how can i achieve this.....

Quote:
9090900819,70.25970354,3.07846452,Metropolitan Transport Project Poonamallee
High Road Chennai Chennai Tamil Nadu India,05-NOV-09 07.22.52.000000000 AM

9090900719,70.25970354,3.07846452,Metropolitan Transport Project Poonamallee
High Road Chennai Chennai Tamil Nadu India,05-NOV-09 07.19.52.000000000 AM

2 rows selected.
if i use set wrap off, row values gets truncated...
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0