As my shell script is calling Db2 many times with an ultra long SQL statement, I would like to abstract the SQL statements from the script and put them into a .sql file, then run it from the Db2 command line processor db2 -f xxx.sql.
I want some of the SQL statements to use variables that are passed in from the shell script.
Is there any method like Oracle's sqlplus that can pass variables inside the .sql file by '&1'?
xxx.sql
SELECT * FROM TABLE_A WHERE FIELD_B > &1
CLP
db2 -f xxx.sql 999
This returns a DB21004E error:
DB21004E You cannot specify both an input file and a command when invoking
the Command Line Processor.
Thank you all the above reply.
Here is my method to dynamically generate the SQL from
.sqlfile byenvsubst. This is highly similar to the originaloracle.sqlfile. Only have to change&Nto$varN.var_stringbecomesvar1=${1} var2=${2}SQL_statementbecomesSELECT * FROM TABLE_A WHERE FIELD_B > 999 AND FIELD_C = 111 ;sed '/^--/d'delete lines with leading--tr "\n" " "replace newline by spacetr -s " "replace sequence of repeated space into 1 space