Shell Script to execute DB2 Stored Procedure

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
horserider
Participant
Posts: 71
Joined: Mon Jul 09, 2007 1:12 pm

Shell Script to execute DB2 Stored Procedure

Post by horserider »

I have a DB2 Stored Procedure that takes input parameter and returns me result set (5 columns ) from cursor. I am able to connect to DB2 Server from my UNIX BOX and run the stored procedure and I get the resultset on my screen. Below is what I do:-

source /mycomp/thisproj/proj/Ascential/DataStage/DSEngine/dsenv
~db2inst1/sqllib/bin/db2
Connect to db2dsn user DB2SPUSER using pass@#45;
CALL SYSPROC.MYSTPROC(?,?,?,?,'U');


I want to write a SHELL SCRIPT that I want to execute and it should save the output data into a TEXT file on my UNIX Server

(1) How do I write a SHELL SCRIPT to do the above steps.
(2) How do I save all my output data into a TEXT file that I will read in my
next job
AmeyJoshi14
Participant
Posts: 334
Joined: Fri Dec 01, 2006 5:17 am
Location: Texas

Post by AmeyJoshi14 »

Hi,
We have implemented the same thing...but our database is Oracle.
Following is the sample script which we use to connect to Oracle and which will save the output in .txt file.

Code: Select all

cat 1.sh

sqlplus username/password@sid <<EOF
spool 1.txt
select sysdate from dual;
exit;
spool off
EOF
The output of the file is :

Code: Select all

cat 1.txt
SQL> select sysdate from dual;

SYSDATE 
--------------- 
14-MAY-08 

SQL> exit;
The file 1.txt can be edited as per the requirement.I hope you will get some idea ... :)
http://findingjobsindatastage.blogspot.com/
Theory is when you know all and nothing works. Practice is when all works and nobody knows why. In this case we have put together theory and practice: nothing works. and nobody knows why! (Albert Einstein)
Post Reply