I am using DB2 database.
I have a query like:
DELETE FROM MYSCHEMA.MY_TABLE WHERE (PROD LIKE 'AB%' OR PROD LIKE 'CD%' OR PROD LIKE 'EF%');
Above query is present in a properties file and I am executing it using a java program.
However, now I want to externalize the where condition.
I have created a new Table PROD_LIKE having a single column PROD_NAME with entries as below:
PROD_NAME
------------
AB
CD
EF
------------
I want to modify the delete query’s where condition such that it uses the entries present in above newly created table.
How can I achieve it ?
DB2 documentation says:
Resolving the problemEven though other databases like SQL Server or Oracle allow the use of database columns for both operands in a “like” comparison, DB2 is more restrictive. When the query database is a DB2 one has to avoid calculations or selects like the above mentioned. There is no way to use a database column as second operand when querying a DB2 and using “like” in a comparison.
What could be the alternative for this ?
In TSQL I’d probably do this,
I’m sure the DB2 SQL is similar as I’m sure this is pretty much ANSI SQL.
You could also try a more general to get rid of the hard coded 2
I don’t see why you need a
likebut yes you can if you want.