Read parameter file in a shell script to unload a DB2 Table???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read parameter file in a shell script to unload a DB2 Table???
# 1  
Old 12-09-2011
Read parameter file in a shell script to unload a DB2 Table???

Hi ,

I Have following requirement:

DB2 Sql query to pass from a parameter file
for example, I would create a parameter file with (SELECT column 1, column 2 FROM Table name) then job would read it and create a file with the contents named table.txt

How to write/modify below ksh script to call the parameter file and write "query out put "to a text file ??

Environment: DB2 tables, AIX, Datastage7.5.2

Shell script: unload.sh (Table name as a parameter )
Code:
#!/bin/ksh
****************************
if [ $# -ne 1 ];
then       
   echo " " >> $JOBLOG_DFLT                                                        
   echo "** Argument missing ** i.e., Table name not passed: " >> $JOBLOG_DFLT
   exit 10;        
fi              
                
TABLENAME=$1;   

*************************
echo " " >> $JOBLOG                                                    
echo " ** Start export of table $TABLENAME ** " >> $JOBLOG 
ls -l  >> $JOBLOG                                                      
echo " " >> $JOBLOG                                                    
####### Unload Table $TABLENAME #######

db2 "EXPORT TO $INST_HOME/$TABLENAME.ext of del SELECT * FROM schema.$TABLENAME FOR FETCH ONLY WITH UR" >> $JOBLOG

Explanation: Here table name is passed as a variable and gives the out put to .ext file but I want to pass the parameter file (in the form of sql query)

Please share your ideas here

Thank you

Moderator's Comments:
Mod Comment Use code tags please, see PM.


---------- Post updated 12-09-11 at 09:22 AM ---------- Previous update was 12-08-11 at 11:06 PM ----------

Hi ,

I am looking at the ksh script to execute a parameter file (which has DB2 sql query stored in it)

Please post your ideas here

Thank you

Last edited by zaxxon; 12-09-2011 at 02:17 AM.. Reason: code tags, see PM
# 2  
Old 12-09-2011
What does your parameter file look like? Is it SQL or just a table of data? Do you need to do any substitution inside it?
# 3  
Old 12-09-2011
Hi,
Parameter file is of format (.ini)consist of Properties and directories:
name=value
Query=select colA,colB FROM schema.tablename (i.e actual query to pass for the table)

I think above approach is works

I welcome more ideas to implement based on my requirement

Thank you
# 4  
Old 12-09-2011
Running db2 9,000 times to process 9,000 lines doesn't sound very efficient. You can feed them in direct and run db2 only once.

You didn't specify what to do with the 'name=' parameter so my script ignores it, chops off the 'Query=' from the front, and prints direct:

Code:
while read LINE
do
        # Skip lines that aren't queries
        [ "${LINE:0:6}" = "Query=" ] || continue

        echo "${LINE:6}" # Echo everything after Query=
done < inputfile | db2

This User Gave Thanks to Corona688 For This Post:
# 5  
Old 12-09-2011
Here we are specifying "sql query" in the script itself ..if it is a small we can accommodate here
Requirements:
We have multiple tables of same format to unload:-
so we want to modify the query often without changing the code (script)i.e without disturbing the code only just modify the sql query in a file.

Sql query=stored in a file and call that file in the script to execute the query

Thanks and welcome for your ideas
# 6  
Old 12-09-2011
Read my code again, it does what you want, unless the file isn't actually as you described it.

If you just stored all the queries in a file, one by one, without the 'value=' and 'query=' stuff, you could feed that file right into db2 raw with no shell script at all.
# 7  
Old 12-09-2011
How to execute your code then ??
using the command line
db2=>
or any other mechanism to unload the DB2 tables ??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell Script to read hive table and send email

HI Team, I am working on reading hive table and send email in email body using shell script, can you please help on fixing the errors: I have 6 columns in my hive table and trying to send the email in the mail body. below script: #!/bin/bash hive -e 'SELECT count(*) from db.table' >... (4 Replies)
Discussion started by: Mi4304
4 Replies

2. Shell Programming and Scripting

Python Script to take file count and insert into DB2 table

Team I have files in different directories . How can i take the count of latest file and insert into Db2 table . I am using awk 'END{print NR+1-ARGC}' (File name) to get the counts. How can i take 1.The count of latest file 2.Insert into Db2 table( File Name and Counts) . cd... (4 Replies)
Discussion started by: Perlbaby
4 Replies

3. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

4. Shell Programming and Scripting

Read parameter file for a shell script

Hi All, I need urgent Help from all of you here. Below is my code- ================================================== #!/usr/bin/sh cd $1 cat $2 | tr -ds "$" "" > parameter_file.param export `parameter_file.param` chmod 777 parameter_file.param echo $1 echo $2 cd $prmDirInput... (5 Replies)
Discussion started by: Amit786
5 Replies

5. Shell Programming and Scripting

How to read a directory as parameter in shell script?

Hi All, I have written a shell script to compile an oracle R12 form and also a procedure is called from it. The procedure registers the form, function and creates a menu entry. I took directory as a parameter. Code is as below: #!/bin/ksh echo... (3 Replies)
Discussion started by: veena484
3 Replies

6. Shell Programming and Scripting

Connect to DB2 table using Shell scripts

Can anyone please help me with an unix shell script to connect a DB2 database. My requirement is just to display the no of records present in a table of a DB2 database through Unix Shell script. Thx - Ram (1 Reply)
Discussion started by: onlyraja
1 Replies

7. Shell Programming and Scripting

How to pass a variable as a parameter to DB2 database from shell script

I need to pass a variable as a parameter from shell script into a DB2 database. var=bhuk_1123_Q_11/22/09 select * from tbl1 where serial_id='$var'; I have tried executing it using db2 -tvf scriptname Somebody please help me out with this. It is throwing an error. Please tell me how... (2 Replies)
Discussion started by: ss3944
2 Replies

8. Shell Programming and Scripting

shell script to read data from text file and to load it into a table in TOAD

Hi....can you guys help me out in this script?? Below is a portion text file and it contains these: GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL005675 000001... (1 Reply)
Discussion started by: pallavishetty
1 Replies

9. Shell Programming and Scripting

How to connect DB2 table using shell script

Hi All, I want to connect two tables in DB2 using shell script and then compare the contents of two tables field by field. Could any one please help me in connecting database tables using Unix and retriving data from the same. Thanks, Durwas (0 Replies)
Discussion started by: dtidke
0 Replies

10. Shell Programming and Scripting

Read from file as script parameter

I have a file with userIDs, one per line no spaces. I have a script that accepts userIDs as a parameter and outputs information about them. What I have had to do in the past was to modify each line of the file with userIDs to call the script with the userID and pipe the output to a data file. ... (2 Replies)
Discussion started by: vmaxx
2 Replies
Login or Register to Ask a Question