Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

db2 sql script file

Tags:

sql

oracle

db2

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

like image 785
smauel Avatar asked Dec 05 '22 05:12

smauel


2 Answers

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.

like image 71
Michael Sharek Avatar answered Dec 27 '22 04:12

Michael Sharek


1) place the filename.sql file in SQLLIB/BIN

2) run db2cmd

3) execute this to connect to the required db

 db2 connect to *dbname* user *userid* using *password*

4) excute this command

 db2 -vtf *filename.sql*

This should execute the sql statements in the file one by one. The sql statements must be ending with a semicolon

like image 40
Abhishek Avatar answered Dec 27 '22 04:12

Abhishek