Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2005
    Posts
    80

    Unanswered: 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

  2. #2
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,
    I don't believe this is possible.
    Grofaty

  3. #3
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Code:
    db2 -t << EOF
    connect to db;
    select * from table;
    EOF
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  4. #4
    Join Date
    Jan 2005
    Posts
    80
    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

  5. #5
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

  6. #6
    Join Date
    Jan 2005
    Posts
    80
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •