Could you please answer similar kind of issues in db2
There's one more option for solving the problem and will not require using dynamic SQL.
You'd have to choose a separator character for your list of values - some character that WILL NEVER be a possible value. I ofter use the caret (^) for that purpose.
Then you should make sure that your parameter is a list of ^ separated values, starting and ending with ^ - "^1^2^3^".
You can create a function which translates your parameter into such a string (something similar to Bigfam's idea).
So if var_Zone_Numbers = '^1^2^3^', then your query will be:
OPEN v_CURSOR FOR
SELECT
FISCAL_YEAR,
FISCAL_PERIOD,
SUM(AMT_USD),
SUM(SM_USD)
FROM
MANAGER_SUMMARY_DATA
WHERE
REPORT_NAME= var_Report_Name AND
var_Zone_Numbers LIKE '%^'||ZONE_CODE||'^%'
GROUP BY
FISCAL_YEAR,
FISCAL_PERIOD;
This way you'll avoid the dynamic sql. The only drawback here is that if there's an index on the zone_code column it will not be used.
You have to decide which will have better performance - the dynamic sql or this solution.
There's one more option for solving the problem and will not require using dynamic SQL.
You'd have to choose a separator character for your list of values - some character that WILL NEVER be a possible value. I ofter use the caret (^) for that purpose.
Then you should make sure that your parameter is a list of ^ separated values, starting and ending with ^ - "^1^2^3^".
You can create a function which translates your parameter into such a string (something similar to Bigfam's idea).
So if var_Zone_Numbers = '^1^2^3^', then your query will be:
OPEN v_CURSOR FOR
SELECT
FISCAL_YEAR,
FISCAL_PERIOD,
SUM(AMT_USD),
SUM(SM_USD)
FROM
MANAGER_SUMMARY_DATA
WHERE
REPORT_NAME= var_Report_Name AND
var_Zone_Numbers LIKE '%^'||ZONE_CODE||'^%'
GROUP BY
FISCAL_YEAR,
FISCAL_PERIOD;
This way you'll avoid the dynamic sql. The only drawback here is that if there's an index on the zone_code column it will not be used.
You have to decide which will have better performance - the dynamic sql or this solution.