Can anyone could help me with this issue, please? I have a cursor defined like this:
CURSOR c_cursorName (
paramA IN VARCHAR2,
paramB IN VARCHAR2)
IS
SELECT tableA.id, tableA.name
FROM tableA
WHERE tableA.fieldA = paramA
AND (paramB IS NULL OR tableA.fieldB = paramB);
Why I'm doing this? Because I want to reuse this cursor in two different cases:
- when I pass a paramB value to return all the rows in tableA where fieldA is equal to paramA value and fieldB is equal to paramB;
- When I don't pass any value in paramB (
nullvalue), and I want to return all the rows in tableA where fieldA is simply equal to paramA (and I don't care about fieldB);
The problem: When I pass null in paramB, my explain plan increase dramatically and I have performance issues.
The easy way to do this is creating two different cursors, one for each case. But I'm trying to find a good and clever solution without the need of creating a new index or a new cursor.
Any suggestions?