The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Delete line in file based on data in another file earth_goddess Shell Programming and Scripting 1 12-29-2008 10:47 AM
Truncating FILE data BASED ON A PATTERN pkumar3 Shell Programming and Scripting 1 10-14-2008 11:49 AM
Rename file based on first 3 characters of data in file jchappel UNIX for Dummies Questions & Answers 3 10-01-2008 02:21 PM
Extracting data from text file based on configuration set in config file suparnbector Shell Programming and Scripting 3 08-10-2007 02:25 AM
Select a portion of file based on query vanand420 Shell Programming and Scripting 14 10-31-2006 04:48 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-26-2009
whoknows whoknows is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 5
Red face How do I use SQL to query based off file data?

This is basically what I want to do:

I have a file that contains single lines of IDs.
I want to query the oracle database using these IDs
to get a count of which ones match a certain condition.
the basic idea is:

cat myfile |
while read id
do
$id in select count(PC.ptcpnt_id)
from ptcpnt_cmpsit PC
where
PC.gndr_type = 'F'
;
done

Hopefully, you get the gist.
  #2 (permalink)  
Old 06-27-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
so you want to use that ID in sql query??
is so
Code:
while read ID ; do 
sqlplus -s username/passwd << EOF
select count(PC.ptcpnt_$ID)
from ...
..
..;
exit;
EOF
done < myfile
  #3 (permalink)  
Old 06-29-2009
whoknows whoknows is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 5
Red face

Thanks! -- I will try this.

---------- Post updated at 10:56 AM ---------- Previous update was at 08:27 AM ----------

OK -- this is what I did:

cat *.sum >> recsum
sort -u -o recsum.sort recsum
print "** Total Records"| tee -a ${logfile}
while read id ; do
sqlplus -s ${lgn} << EOF | tee -a ${logfile}
select count(PC.tran_nbr)
from ptcpnt_cmpsit PC
where
PC.ptcpnt_id = $id
and PC.gndr_type = 'F'
;
exit;
EOF
done < recsum.sort
print "\n${sn}: COMPLETE [$(date)]:
Output appended to log file [${logfile}]
" | tee -a ${logfile}
echo > recsum

Assume I have a couple of files named *.sum in my directory.
My output is going to the logfile, but it is also going to the screen:
COUNT(PC.PTCPNT_ID)
----------------------
0
1 row selected.

COUNT(PC.PTCPNT_ID)
----------------------
1
1 row selected.

COUNT(PC.PTCPNT_ID)
----------------------
0
1 row selected.

I don't want it to go to the screen. It also seems to be in an infinite loop. It never ends. This is an example of a couple of rows in my file (total rows around 5000):

600010001
600010060
600010065
600010070
600010090
600010120
  #4 (permalink)  
Old 06-29-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
Quote:
My output is going to the logfile, but it is also going to the screen:
thats because you are using tee command(use only >>)
read man page of tee.. tee command will display the o/p on screen and redirect it to file also..
  #5 (permalink)  
Old 06-30-2009
whoknows whoknows is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 5
Red face

Thanks -- that took care of it. The while loop is working. It is just
verrrrrrrrrrrrrrrrrrrrrrrrrrrrrry slow. I'll have to figure out a better way to
do this.
Thanks for your help.
Sponsored Links
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 03:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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