0

I want a stored function like so:

create function myFunction (someSwitch boolean)
return ...
is
  cursor myCursor (params) is
    [BIG QUERY];
...

Where the BIG QUERY can have an extra WHERE clause if someSwitch is true.

Can this be done within the cursor definition and, if so, how? Otherwise, what would be my options: I'm thinking that I could either create two cursors (one with the extra clause, the other without) and then do the logic in the function body. I'm not very satisfied by this approach as the query is very big and I would want to avoid repeating code. Alternatively, I could create the cursor SQL dynamically; but this would incur a performance degradation, right?

Thanks :)

2
  • 2
    You'll have to go the dynamic SQL way. Commented Jan 13, 2012 at 9:37
  • I thought so :( Never mind: It turns out that my cursor can't access out-of-schema objects, anyway, so it's dead in the water before it starts!... Thanks for your help :) Commented Jan 13, 2012 at 9:57

1 Answer 1

4

You can add the where in this way:

where (some_condition or the_other_conditions)

AFAIK oracle will do shortcut OR. That is: if some_condition is true then the_ohter_condition will not be evaluated(and, anyway, this is not important).

Sign up to request clarification or add additional context in comments.

1 Comment

PL/SQL will use the typical short-circuit evaluation, but in Oracle SQL "Left to right evaluation is not guaranteed for multiple conditions connected using OR" - docs.oracle.com/cd/E11882_01/server.112/e26088/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.