Writing sql results to file using ksh -nevermind


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Writing sql results to file using ksh -nevermind
# 1  
Old 04-07-2010
Writing sql results to file using ksh -nevermind

I'm having problems with writing my sql results to a file:

Code:
sqlplus -S username/password@DB <<!!

set echo off
set verify off
set showmode off
set feedback off 
set timing off
set linesize 250 
set wrap off
set pagesize 0
set newpage none
set tab off
set trimspool on
set colsep ','

spool $TVXTEMP
select acct_id, customer_name, amount, date, phone_num
from table;
spool off

function createfile {
rm -f $1
awk -v typ="$3" -v prdt=$(date '+%m/%d/%Y') -v fout=$1 \
   'BEGIN {FS=",";c=1; 
           fmt="%-10s %-30s %-10s %-10s %-10s\n";
           printf "acct_id,customer_name,amt,date,phone_num,call_loc\n" > fout;
   /^'$3'/ {printf "%s,%s,%s,%s,%s,%d\n",$1,$2,$3,$4,$5,c > fout;
           if (c<=6) c+=1; else c=1;
           printf fmt,$1,$2,$3,$4,$5 > fout}' $TVXTEMP
}

file1=file1.txt

createfile $file1

The file just prints the first 2 columns - acct_id, customer_name. I think the results are not written to $TVXTEMP correctly, and I don't know how to fix it..

---------- Post updated at 01:55 AM ---------- Previous update was at 01:48 AM ----------

Nevermind, I figured it out already. Smilie
# 2  
Old 04-07-2010
Consider letting us know how you solved it next time, please.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Oracle/SQLPlus help - ksh Script calling .sql file not 'pausing' at ACCEPT, can't figure out why

Hi, I am trying to write a script that calls an Oracle SQL file who in turns call another SQL file. This same SQL file has to be run against the same database but using different username and password at each loop. The first SQL file is basically a connection test and it is supposed to sort... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Ksh: How to write the log file simultaneously when .sql file executes by UNIX process

Hello Team- we would like to implement an approach which has to write the log file simultaneously when .sql file is executing by Unix process. At present,it is writing the log file once the process is completed. I've tested the current process with the below approaches and none of them... (1 Reply)
Discussion started by: Hima_B
1 Replies

3. Shell Programming and Scripting

How to store results of multiple sql queries in shell variables in ksh?

Hi, I have a script where I make a sqlplus connection. In the script I have multiple sql queries within that sqlplus connection. I want the result of the queries to be stored in shell variables declared earlier. I dont want to use procedures. Is there anyway else. Thanks in advance.. Cheers (6 Replies)
Discussion started by: gonchusirsa
6 Replies

4. Shell Programming and Scripting

[Shell/Perl(?)] Prepending timestamps to console output & writing results to a file

I do a lot of TSM work and I embarked on what I thought would be an easy task, and I'd be very happy for any input to save the pounding my keyboard is receiving :] By default, the output of TSM's console has no timestamping, making it hard to sort through accurately. This puts my console into... (5 Replies)
Discussion started by: Vryali
5 Replies

5. Shell Programming and Scripting

To create a file writing a SQL into it from another file

Hi, I have a file in which I have database information along with 1 SELECT statement. Only 1 statement would be there. I want to grep this SELECT STATEMENT only and write into a separate file. Input File format: Database_Name:<database> Schema_Name:<schema> Table_Name:<table> Select *... (3 Replies)
Discussion started by: ustechie
3 Replies

6. Shell Programming and Scripting

Export SQL results to .TXT file for emailing

Hi everyone, I am new to unix and bash and in need of some help. I am writing a script that will execute a SQL query. The script runs and the SQl query runs, but I cannot figure out how to save the results as a file that can be emailed to a user. Here is my scripts thus far: #!/bin/sh SID=$1... (2 Replies)
Discussion started by: alpinescott
2 Replies

7. Shell Programming and Scripting

writing the output of SQL into one file

Hi All, Please help me writing the below script. I have two sql queries. 1. Select count(1),Client_id from TABLE_A group by Client_id; 2. Select count(1),Client_id from TABLE_B group by Client_id; I need the output of above two sql queries in a single file. The output 2nd query should be... (4 Replies)
Discussion started by: 46019
4 Replies

8. UNIX for Dummies Questions & Answers

store SQL statements and results in a file

Hello Guys... I want a small help from you guys. Actually in Oracle, we are having a utlity called spool through which can store whatever SQL statements executed and other queries and the output of those queries in a file So, similarly in Unix, if I start a session executing a number of Unix... (2 Replies)
Discussion started by: mraghunandanan
2 Replies

9. Shell Programming and Scripting

Catch a PL/SQL exception in ksh file

Hi all Im trying to call a PL SQl block from a ksh file like this : sqlplus -s $DB_USERID/$DB_PASSWD@$DB_NAME<<eof whenever SQLERROR exit 1 var varError VARCHAR2(200); exec ODAS_BATCH_JOBS_RETRIEVE.retrieve_user_info(:varError); eof If there is a error then varError will return a... (1 Reply)
Discussion started by: Sam123
1 Replies

10. Programming

Writing to a File using pl/sql

Hi I am new to using pl/sql on a unix platform and am having trouble writing to a file from within a block. Below is an example of the code that I have. I know that I need to use UTL_FILE to accomplish this; however, I keep getting errors. Can someone please help me? I am trying to create a... (1 Reply)
Discussion started by: stky13
1 Replies
Login or Register to Ask a Question