Hi! I need to check, if procedure parameters are null, and if not, to use it in WHERE clause. For example:
sqlquery := 'SELECT * FROM table WHERE a_col = a AND';
IF b IS NOT NULL THEN
sqlquery := sqlquery || ' b_col = :b';
END IF;
IF c IS NOT NULL THEN
sqlquery := sqlquery || ' c_col = :c';
END IF;
And so on.
Then I need to use OPEN-FOR-USING statement to open cursor for formed sqlquery, but previously I should decide, which values to send by USING clause. The only way I see is to use lots of IF clause:
IF b IS NOT NULL AND c IS NOT NULL THEN
OPEN cur FOR sqlquery USING b, c;
ELSIF b IS NOT NULL THEN
OPEN cur FOR sqlquery USING b;
ELSIF c IS NOT NULL THEN
OPEN cur FOR sqlquery USING c;
ELSE
OPEN cur FOR sqlquery;
For N values I get large amount of IF clauses. How can I slove this problem without lots of IFs? I think there can be used Oracle Collections, but I didn't find any example of it.