![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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:
Quote:
|
|
||||
|
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 |
|
||||
|
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:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|