NoDisplayName
NoDisplayName

Reputation: 15736

How to avoid multiple function executions in case expression without nesting

So let's assume I have the following query:

SELECT
  CASE
  WHEN SOME_PACKAGE.SOME_EXPENSIVE_FUNCTION IS NOT NULL
    THEN SOME_PACKAGE.SOME_EXPENSIVE_FUNCTION || ', random string'
  ELSE
    'something_else'
  END
FROM
  SOME_TABLE;

Is there a way to prevent this package function from executing more than once without nested queries?

Upvotes: 2

Views: 40

Answers (1)

KevinKirkpatrick
KevinKirkpatrick

Reputation: 1456

This should work:

SELECT NVL(NULLIF(SOME_PACKAGE.SOME_EXPENSIVE_FUNCTION
  ||', random string',', random string'),'something_else')
FROM SOME_TABLE;

Upvotes: 3

Related Questions