If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > connect and run the query in the same db2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-04-07, 02:53
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
 
Join Date: Jan 2005
Posts: 75
connect and run the query in the same db2

hi ,

is it possible to connect to db2 instance and run the query in same DB2 instance???

something like this( I know this is not the right syntax)

echo "select * from table" | db2 "connect to DB user xxxx using xxxx"

thanks
Reply With Quote
  #2 (permalink)  
Old 05-04-07, 04:08
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,
I don't believe this is possible.
Grofaty
Reply With Quote
  #3 (permalink)  
Old 05-04-07, 04:09
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Code:
db2 -t << EOF
connect to db;
select * from table;
EOF
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #4 (permalink)  
Old 05-04-07, 05:01
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
 
Join Date: Jan 2005
Posts: 75
Thanks its working. However, it is also printing the unwanted messages. so I want to capture the error messages seperately, data seperately and suppress the unwanted messages like


Database server = DB2/AIX64 8.2.2
SQL authorization ID = xxxxxxx
Local database alias = xxxxxxx
Reply With Quote
  #5 (permalink)  
Old 05-04-07, 05:26
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
True. You are starting a regular db2 clp, and that comes with all the things that are written to standard output. What you can do is to get rid of the CLP output itself:
Code:
db2 -tz output &>/dev/null <<EOF
connect to db;
select * from syscat.tables fetch first 10 rows only;
EOF
However, you will still see the output from the CONNECT operation, data and DB2 messages in the "output" file. You could add the option -x to suppress column headers or -a to add SQLCA output (or whichever other options you can use).

Separating the different output messages is a different story. First, how would you want to separate them? Write things to different files? Or use different output streams? If the latter, which streams do you have in mind? I believe you have only two options:
(1) Parse the output yourself (using Perl or whichever programming language you prefer for such a task, or
(2) Do not use the DB2 CLP but implement a small application of your own.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #6 (permalink)  
Old 05-04-07, 10:38
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
 
Join Date: Jan 2005
Posts: 75
Stolez thanks a lot, Why i asked that was just to make it neat. anyways, I have managed to do it with the shell script
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On