THanks Brian.
So now I have written the following shell script to connect to a db2
database and execute a query. Is there any better way / alternate way
of doing this?
#!/usr/bin/ksh
db2 +t connect to <dbname>;
SQLSTMT=/tmp/$0.$$.tmp
echo $SQLSTMT
cat <<EOF > $SQLSTMT
set schema ADMIN;
EXPORT TO x.unl OF DEL MODIFIED BY NOCHARDEL
select * from store;
EOF
db2 -txf $SQLSTMT
echo $?
Thanks,
Sohan
P.S. I am new to db2 and UNIX.
> THanks Brian.
>
[quoted text clipped - 16 lines]
> db2 -txf $SQLSTMT
> echo $?
Looks good. You probably want to remove the temp file afterwards, though.
If your SQL statements are not too complex, you can also do this:
#!/bin/sh
db2 "CONNECT TO <dbname>"
db2 "SET SCHEMA = admin"
db2 "EXPORT TO x.unl OF DEL MODIFIED BY NOCHARDEL SELECT * FROM store"

Signature
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
> THanks Brian.
>
[quoted text clipped - 42 lines]
> >
> > B.
Instead of cat to a file and running the file, the statement itself can
be used:
db2 -txf <<EOF > $SQLSTMT
set schema ADMIN;
EXPORT TO x.unl OF DEL MODIFIED BY NOCHARDEL select * from store;
EOF
Of course, if only one statement is used, the SET SCHEMA is extraneous,
and the schema could be mentioned as part of the TABLE name. This would
make it one statement, and obviate the need for a here-document.
db2 -tx "EXPORT TO x.unl OF DEL MODIFIED BY NOCHARDEL select * from
ADMIN.store;"
Of course, the asterisk may then cause globbing issues, so it needs to
be escaped, or the statement needs to be quoted. Further, with one
statement, the semi-colon is redundant, making the most efficient
statement:
db2 -x EXPORT TO x.unl OF DEL MODIFIED BY NOCHARDEL select \* from
ADMIN.store
If you are looking to automate exporting and loading multiple TABLE, i
just wrote a script to do that (with some very kind help from this
newsgroup).
B.
teckguan - 26 Dec 2007 03:13 GMT
Hi Brian,
I am still new to db2 and not really understand the coding part.
db2 -txf <<EOF > $SQLSTMT
set schema ADMIN;
EXPORT TO x.unl OF DEL MODIFIED BY NOCHARDEL select * from store;
EOF
I have a few questions that I hope that you can help me by explaining it.
Thanks.
1. If I have several tables to be executed through Shell scripts, can I use
the same command?
2. For $SQLSTMT in the coding, I would like to ask is that the database name?
3. For << EOF > in the coding, may I know what is the meaning of it?
Thanks.
Regards,
Teck Guan.
>> THanks Brian.
>>
[quoted text clipped - 30 lines]
>
>B.