tags:

views:

1573

answers:

2

Hi all,

I have an oracle script that I am trying to convert to valid db2 syntax. Within this sql file I have various calls to other sql files passing in a parameter using the '@' syntax.

e.g.

@script1 param1
@script2 param2

Can anyone help me with valid db2 equivalent statements? Is there an equivalent run command in db2? is it possible to pass parameters to a sql script in db2?

thanks,

smauel

+3  A: 

The thing you are after is the DB2 Command Line Processor (CLP).

If you want to execute a script, you would execute in the CLP:

db2 -vtf script1

-f tells the CLP to run command input from the given file.

Here's the full list of options.

Unfortunately db2 doesn't support passing parameters to a script. You would have to combine your db2 -vtf commands with other scripting commands (such as sed) to generate the scripts for you, as in this example.

Michael Sharek
+1  A: 

There is an easier way for passing in parameters, that works fine for us (it might not work with (complex) multiline sql statements).

Convert your sql-script into a shell script by adding 'db2 ' at the beginning of each line. Than you can use the standard variable replacement syntax from your shell in your scripts.

so instead of

insert ...
update ...

you will have

db2 insert ...
db2 update ...
Peter Schuetze