0

I am facing a problem in DB2. In my Oracle environment it was very easy for me to include multiple scripts in one master script, which were executed sequentially. e.g.: Master.sql:

  • connect ....
  • @script1.sql
  • @script2.sql

Now I have to build up same logic in DB2 LUW. Is there a simple way to include multiple scripts in one master script? I would like to have one single db2 call from shell, which executes the master script and within all subscripts.

Regards Jan

WarrenT
  • 4,502
  • 19
  • 27
cyruz
  • 37
  • 1
  • 1
  • 6

2 Answers2

0

There is notrhing to stop you from creating a single file with multiple sql batches. In the Windows world, it would look like this:

Note: First you initialize the db2 command prompt.

 db2cmd -c -w -i %1.bat

With as many of these as you want in the .bat file:

 db2 -txf c:\Example\db2html.sql
smoore4
  • 4,520
  • 3
  • 36
  • 55
  • I am working in an unix environment. My client is 10.5 and hasnt got the db2cmd (maybe it is called different in version 10.5?!) – cyruz Nov 04 '13 at 08:45
  • I think in Linux you do not need to initialize the db2 command prompt. You can just type in db2 and the command, so you put them in a shell script. Something like this: db2 connect to yourdb; db2 -txf /home/usr/mysql1.sql; db2 terminate; – smoore4 Nov 04 '13 at 09:14
0

In Linux, the db2clp is included in the shell once you load the db2profile ('. /home/db2inst1/sqllib/db2profile). In windows, you need to call db2cmd in order to use db2clp.

With a interactive db2clp, you cannot call db2 scripts via @scriptX, however, you can call them from the shell like

db2 -tvf script

However, if you use the CLP*Plus you can do almost everything you do in SQL*Plus. For more information: https://www.ibm.com/developerworks/community/blogs/IMSupport/entry/tech_tip_db2_s_new_clp_plus_utility?lang=en

AngocA
  • 7,655
  • 6
  • 39
  • 55