Running Sql scripts accross db2


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running Sql scripts accross db2
# 1  
Old 10-23-2008
Running Sql scripts accross db2

Hi,

I would be really thankful, if anyone could help me out with this,since i am very new to this shell scripting.
I have 6 sql scripts that i am trying to run in unix across db2.
i want the scripts to be executed as follows,
script_1 should be executed first.
Then script_2,script_3,script_4,script_5 should be executed simultaneously.
Once, after all these are done with execution, i need to execute script_6

Thanks in advance,
Ridley.
# 2  
Old 10-23-2008
below is the code which will execute the sql command/existing .sql files in oracle. before doing this you have to provide the ORAUSER, ORAPWD and SPOOLFILE. This should be in the path where you having all the 6 .sql sciprt files. Try and let me know.

Code:
ORAUSER="oracle_username"
ORAPWD="oracle_password"
SPOOLFILE="spool filename"
 
sqlplus -s $ORAUSER/$ORAPWD >/dev/null <<!
        set show off
        set term off
        set termout off
        set trimspool on
        set verify off
        set feedback off
        set pagesize 0
        set long 2048
        set longchunksize 2048
        set linesize 2048
        set trimspool on
        set trim on
        SPOOL $SPOOLFILE
        @script1.sql
        @script2.sql
        @script3.sql
        @script4.sql
        @script5.sql
        @script6.sql
        SPOOL OFF;
!

# 3  
Old 10-23-2008
sry.., but i need to run this across db2
# 4  
Old 10-23-2008
Assuming your sql scripts are @ delimited
You might want to provide full path for db2 command,
#!/bin/ksh
db2 -td@ -vf script_1
db2 -td@ -vf script_2 &
db2 -td@ -vf script_3 &
db2 -td@ -vf script_4 &
db2 -td@ -vf script_5 &
wait
db2 -td@ -vf script_6

Is this what you are looking for ?
# 5  
Old 10-23-2008
or you can just use
read sql script into a string variable sqltext,
db2 -x +w <sqltext>
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Call parallel sql scripts from shell and return status when both sql are done

Hi Experts: I have a shell script that's kicked off by cron. Inside this shell script, I need to kick off two or more oracle sql scripts to process different groups of tables. And when both sql scripts are done, I will continue in the shell script to do other things like checking processing... (3 Replies)
Discussion started by: huasheng8
3 Replies

2. Shell Programming and Scripting

Help in executing the following db2 sql querry in unix

Hi All, Please help me out in executing the following db2 querry in unix db2 "select AP_RQ_ACQ_INST_ID || ',' || txn_classifier || ',' || AP_RS_RESP_CD || ',' || (count(*) AS COUNT1) || ',' || (SUM(AP_RQ_TXN_AMT) AS TOTAL_AMT) from TXN_RECORD where CREATE_TS > '2010-11-22 11:00:00.008645' ... (1 Reply)
Discussion started by: dudd9
1 Replies

3. Shell Programming and Scripting

Execute multiple SQL scripts from single SQL Plus connection

Hi! I would like to do a single connection to sqlplus and execute some querys. Actually I do for every query one connection to database i.e echo 'select STATUS from v$instance; exit' > $SQL_FILE sqlplus user/pass@sid @$SQL_FILE > $SELECT_RESULT echo 'select VERSION from v$instance;... (6 Replies)
Discussion started by: guif
6 Replies

4. Programming

db2 sql and Java Gui's

Hi Everyone, I'm basically trying to rewrite a korn shell script that currently runs and execute a db2 SQL and then it presents the output below to the users. I wonder how I can achieve the same in Java using GUI's. Any advise / comments would be highly appreciated. Thanks. DBNAME ... (1 Reply)
Discussion started by: arizah
1 Replies

5. 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

6. Shell Programming and Scripting

Reading values from a file using DB2 SQL

I have some alphbetical codes in that (1 Reply)
Discussion started by: kavithakuttyk
1 Replies

7. Shell Programming and Scripting

running db2 sql and exporting output from ksh scipt

Hi there, I am trying to write a shell script as root on AIX 5.3 where I change user to db2inst1, connect to our db2 database, run a sql select query and export the result of the query to a file. The code I have so far is as follows:- #!/usr/bin/ksh su - db2inst1 -c "db2 connect to... (0 Replies)
Discussion started by: candlino
0 Replies

8. Shell Programming and Scripting

Calling SQL LDR and SQL plus scripts in a shell script

Hi- I am trying to achieve the following in a script so I can schedule it on a cron job. I am fairly new to the unix environment... I have written a shell script that reads a flat file and loads the data into an Oracle table (Table1) via SQLLDR. This Works fine. Then, I run a nested insert... (5 Replies)
Discussion started by: rajagavini
5 Replies

9. Shell Programming and Scripting

Running SQL Scripts from Shell script - Need insight!

I've a script that fetches various values from the database as below: #! /bin/ksh $conn="user/pwd@service_name" `sqlplus -s << $conn EOF1 @xyz.sql @pqr.sql @abc.sql EOF1` The output of the script should generate txt files containing the results from queries which are further... (6 Replies)
Discussion started by: manthasirisha
6 Replies

10. Shell Programming and Scripting

SQL scripts not running, possible timeout issue?

I am a novice Unix scripter and need a little advice/help on a script I've written that's causing some problems. We are using Solaris 9 on a Sun box and the script is invoked with the korn shell. I have a two-part question: I wrote a shell script that calls and executes 3 separate sql scripts,... (3 Replies)
Discussion started by: E2004
3 Replies
Login or Register to Ask a Question