Wednesday, August 1, 2012

Run multiple commands in db2cmd

In Windows DOS, you need to run db2cmd before you can do any db2 command. If you want to run multiple commands, usually you can output the commands into a file and call db2cmd like this:
db2cmd -c db2 -tvf cmd_file.sql
But if you don't want to generate a file, here is how
db2cmd -c db2 connect to mydb user me using passwd && db2 select * from my_table && db2 terminate
DOS uses && to run multiple commands in one line.

2 comments:

  1. I tried in that way. It is not working. Please try to assist me.

    ReplyDelete
    Replies
    1. What's the error? Could you try to double quoted the commands?
      db2cmd -c "db2 connect to mydb user me using passwd && db2 select * from my_table && db2 terminate"

      Delete