Trouble with external tables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trouble with external tables
# 1  
Old 10-03-2011
Trouble with external tables

Hi All,

My flat file lets say has the following contents

HTML Code:
AT & T
CITIZENS MOHAVE CELLULAR
COMMNET
DRR
E1CELLULAR
....
Now, Im trying to select data from a flat file(sitting on unix server) and want to run a simple query as below(running Oracle 10g)

HTML Code:
SELECT MO_IDENTIFER, SERVICE_PROVIDER FROM MVNO_SP WHERE SERVICE_PROVIDER IN (....
FLAT FILE CONTENTS.
);
I only have READ privileges on this db & hence external tables are not option. So, how do I do a look up on this file & then run a select based on the value of the MVNO Operator generated from the above file. In other words, how do I construct a sql statement where in the value of each row is passed to a variable and that variable is used to read data from the db as below


HTML Code:
SELECT MO_IDENTIFER, SERVICE_PROVIDER FROM MVNO_SP WHERE SERVICE_PROVIDER IN (
'AT & T',
'CITIZENS MOHAVE CELLULAR',
'COMMNET'
.....
);
I been staring at various postings on this topic for a while now and so far, not thing has been posed on the lines of what Im talking about here as everyone has chosen the option of external tables where in we specify the directory that it has to be read from, define the file format etc etc..

Please help.

regards,
PGonzalez.
# 2  
Old 10-03-2011
An example using the dual table just for demonstration:

Code:
printf 'select %s from dual;' "$(
  printf "'%s'\n" $(<infile) |
    paste -sd, -
    )" |
      sqlplus -S '/ as sysdba'

The output is:

Code:
$ cat infile
AT & T
CITIZENS MOHAVE CELLULAR
COMMNET
DRR
E1CELLULAR
$ printf 'select %s from dual;' "$(
>   printf "'%s'\n" $(<infile) |
>     paste -sd, -
> )" |
>   sqlplus -S '/ as sysdba'

'A ' ' 'CITIZEN 'MOHAV 'CELLULA 'COMMNE 'DR 'E1CELLULA
-- - - -------- ------ -------- ------- --- ----------
AT & T CITIZENS MOHAVE CELLULAR COMMNET DRR E1CELLULAR


So, if I understand the requirement correctly, you'll need something like this:

Code:
printf 'SELECT MO_IDENTIFER, SERVICE_PROVIDER 
        FROM MVNO_SP WHERE SERVICE_PROVIDER IN (%s);' "$(
  printf "'%s'\n" $(<infile) |
    paste -sd, -
    )" |
      sqlplus -S <connect_string>

# 3  
Old 10-03-2011
radoulov,

The script errors with the following msg -
Code:
hdflldRR3:/Users/PGonzalez 06:26:57 cat SBR.sh 

printf 'select %s from dual;' "$(
  printf "'%s'\n" $(<infile) |
     paste -sd, -A
 )" |
   sqlplus -s "db info"



hdflldRR3:/Users/PGonzalez 06:27:01 SBR.sh 
paste: illegal option -- A
usage: paste [-s] [-d delimiters] file ...
select	from dual
        *
ERROR at line 1:
ORA-00936: missing expression


paste: illegal option -- A
usage: paste [-s] [-d delimiters] file ...
select	from dual
        *
ERROR at line 1:
ORA-00936: missing expression


Last edited by PG3; 10-03-2011 at 11:33 AM.. Reason: Code tags.
# 4  
Old 10-03-2011
There's no -A in my code ...
# 5  
Old 10-03-2011
Radoulov,

That was a deliberate mistake by me. At anyrate, I shall let you know how it goes as I need to get off the shift now but when I just ran the script on dual table, it did show the following

Code:
AT & T CITIZENS MOHAVE CELLULAR COMMNET DRR E1CELLULAR

thanks a bunch again & grateful for the help provided.

regards,
PGonzalez.
# 6  
Old 10-03-2011
You're welcome!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

How to arhive hive external tables?

Hi Guys, Is there a way to check hive external tables which are created 90 days before and drop those tables along with underlying hdfs data. Can this be achieved in unix script? (10 Replies)
Discussion started by: Master_Mind
10 Replies

2. Shell Programming and Scripting

Compare with 2 tables

I have 3 file inputs, file1 20160302|5485368299953|96|510101223440252|USA|5485368299953|6|800|2300|0 20160530|5481379883742|7|510101242850814|USA|5481379883742|5|540|2181|1500 20160513|5481279653404|24|510100412142433|INDIA|5481279653404|3|380|1900|0... (1 Reply)
Discussion started by: radius
1 Replies

3. Programming

C++ Dictionaries and tables

I was looking at this code from a programming book: #include <time.h> #include <iostream> #include <string> #include <deque> #include <map> #include <vector> #include <cstdlib> using namespace std; const int NPREF = 2; const char NONWORD = "\n"; // cannot appear as real line: we... (1 Reply)
Discussion started by: totoro125
1 Replies

4. UNIX for Dummies Questions & Answers

Mysqldump certain tables

Hi, I have to upload part of my database periodically when i make changes to product data etc. However I only want to upload certain tables. We suffer from bandwidth chock here, so i want to write a couple of separate scripts that upload parts of the database that changed. The database is large... (5 Replies)
Discussion started by: timgolding
5 Replies

5. Shell Programming and Scripting

Display tables of 6

I'm new to linux and unix I would like to know how to display tables of 6 line after line Output should be 1*6 = 6 2*6 = 12 3*6 = 18 4*6 = 24 etc I can display line by line but not continuously Any suggestion (3 Replies)
Discussion started by: electricair
3 Replies

6. Shell Programming and Scripting

Tables and borders

when i do this: cat HITS i get the following displayed: sport.hits:87.114.172.31 Thu Sep 28 22:45:12 GMT 2006 how do i put this information into a bordered table? so it will output like this: ...........File /... (9 Replies)
Discussion started by: amatuer_lee_3
9 Replies

7. Shell Programming and Scripting

Converting tables of row data into columns of tables

I am trying to transpose tables listed in the format into format. Any help would be greatly appreciated. Input: test_data_1 1 2 90% 4 3 91% 5 4 90% 6 5 90% 9 6 90% test_data_2 3 5 92% 5 4 92% 7 3 93% 9 2 92% 1 1 92% ... Output:... (7 Replies)
Discussion started by: justthisguy
7 Replies

8. UNIX for Dummies Questions & Answers

Routing tables

Hey guys, I needed to add a route to my routing table and I got it to work but on reboot it gets removed. Anyone know what file I can add this route to so it stays on the machine after a reboot? (9 Replies)
Discussion started by: kingdbag
9 Replies

9. UNIX for Dummies Questions & Answers

viewing tables

I have completely blanked out on this and I have done it a million times. I need to modify some tables in unix. What is the command for opening/viewing the tables? Thanks so much. :o (2 Replies)
Discussion started by: itldp
2 Replies
Login or Register to Ask a Question