Created
October 27, 2014 09:44
-
-
Save velll/08a4a1cf3c0ab7097da1 to your computer and use it in GitHub Desktop.
PL/SQL short-cut evaluation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Coalesce has short-cut evaluation so it does not evaluate second parameter if the | |
| -- first one is ok | |
| DECLARE | |
| num_Result NUMBER; | |
| num_Something NUMBER := 1; | |
| -- | |
| FUNCTION RAISES | |
| RETURN NUMBER | |
| IS | |
| BEGIN | |
| RAISE_APPLICATION_ERROR(-20100, 'Here be dragons'); | |
| RETURN 0; | |
| END RAISES; | |
| BEGIN | |
| num_Result := COALESCE(num_Something, RAISES); | |
| RAISE_APPLICATION_ERROR(-20101, num_Result); | |
| END; | |
| / | |
| -- If it is not, wll, then everything goes as expected | |
| DECLARE | |
| num_Result NUMBER; | |
| num_Something NUMBER; | |
| -- | |
| FUNCTION RAISES | |
| RETURN NUMBER | |
| IS | |
| BEGIN | |
| RAISE_APPLICATION_ERROR(-20100, 'Here be dragons'); | |
| RETURN 0; | |
| END RAISES; | |
| BEGIN | |
| num_Result := COALESCE(num_Something, RAISES); | |
| RAISE_APPLICATION_ERROR(-20101, num_Result); | |
| END; | |
| / | |
| -- NVL has no short-cut evaluation | |
| DECLARE | |
| num_Result NUMBER; | |
| num_Something NUMBER; | |
| -- | |
| FUNCTION RAISES | |
| RETURN NUMBER | |
| IS | |
| BEGIN | |
| RAISE_APPLICATION_ERROR(-20100, 'Here be dragons'); | |
| RETURN 0; | |
| END RAISES; | |
| BEGIN | |
| num_Result := NVL(num_Something, RAISES); | |
| RAISE_APPLICATION_ERROR(-20101, num_Result); | |
| END; | |
| / |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment