Sorry, slight misunderstanding there. You wanted to call a SQL script from within a SQL script. I don't think you can do this. As I said, DB2 CLI isn't like SQL*Plus - it has hardly any programming capabilities at all.
Dagon,
I totally agreed with you.
Now, is there a way to do select and base on the select result to invoke a DB2 SQL script from command line?
Any scripting language such as REXX or DOS command that will allow such a thing?
What I want to achieve is this:
-- pseude code...
DB2 CONNECT TO $mydb USER $user1 USING $pw1
DB2 SELECT col1 INTO $var1 FROM tab1 WHERE col2 = $user1
if [[-z $var1]]; then
myscript1.sh
fi
As I said, DB2 isn't a scripting language. The only way you are going to able to do something like that is to wrap a shell script around it or perhaps use a stored procedure instead.
If it's of any help, you can use shell scripts as a way of getting parameters into db2. I use stuff like:
db2_cmd="delete from table where column = '$1'"
db2 -s $db2_cmd
if [ "$?" -gt 2 ]
then
exit 4
fi
As for getting data back from db2, the only option I can think of would be to write it out to a file by capturing the output e.g.
db2 -t -f script.sql > x.x
I've not found any way of suppressing the headings and other stuff, so your best bet might be to preface the output with some sort of string so that you can locate it easily e.g.
DB2 SELECT 'QUERY RESULT: '||col1 INTO $var1 FROM tab1 WHERE col2 = $user1
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.