16.10.2015 Views

Getting Started with DB2 Express-C

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5 – <strong>DB2</strong> Tools 101<br />

used a semi-colon for the statement terminator, there would have been a conflict in the<br />

script <strong>with</strong> the one used for the SELECT statement, resulting in an error reported by <strong>DB2</strong>.<br />

CREATE FUNCTION f1()<br />

SELECT … ;<br />

…<br />

END!<br />

Listing 5.2 - Contents of the script file functions.db2<br />

To inform <strong>DB2</strong> that a different statement termination character is being used, use the -d<br />

flag, followed by the terminator character desired as shown below:<br />

db2 –td! –v –f functions.db2 –z functions.log<br />

To find out more about the other flags that can be used from the Command Window or<br />

Linux shell, use this command:<br />

db2 list command options<br />

5.10.2 Operating system (shell) scripts<br />

Operating system scripts provide greater flexibility and power than SQL scripts, as they<br />

give you the possibility to add additional programming logic. They are platform dependant,<br />

but they support parameters and variables. Listing 5.3 shows an example of a simple<br />

Windows operating system (shell) script.<br />

set DBPATH=C:<br />

set DBNAME=PRODEXPR<br />

set MEMORY=25<br />

db2 CREATE DATABASE %DBNAME% ON %DBPATH% AUTOCONFIGURE USING<br />

MEM_PERCENT %MEMORY% APPLY DB AND DBM<br />

db2 CONNECT TO %DBNAME% USER %1 USING %2<br />

del schema.log triggers.log app_objects.log<br />

db2 set schema user1<br />

db2 –t –v –f schema.db2 –z schema.log<br />

db2 –td@ -v –f triggers.db2 –z triggers.log<br />

db2 –td@ -v –f functions.db2 –z functions.log<br />

Listing 5.3 - Contents of the operating system script file create_database.bat<br />

To execute this operating system script from the command line, you would issue the<br />

following command on Windows:<br />

create_database.bat db2admin ibmdb2<br />

where db2admin is the userID and first parameter of the script, and ibmdb2 is the<br />

password and second parameter of the script.<br />

On Windows using the “bat” extension tells the operating system that this is a batch<br />

executable file. On Linux, you need to change the mode on the file to indicate the file is

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!