This Oracle function gives us the ability to have a function with an IF-THEN-ELSE type of construct.
The Oracle CASE WHEN Construct often provides a clearer explanation of the logic.
EXPRESSION | The value you wish to evaluate |
SEARCH1 | The value that is compared to the Expression |
RESULT1 | What is returned if the Expression is equal to the value |
SEARCH2 | (optional) The value that is compared to the Expression |
RESULT2 | (optional) What is returned if the Expression is equal to the value |
DEFAULT | (optional) What is returned if the Expression is not equal to any of the values provided. |
If the optional Default value is included, then this is what is returned if the expression is not equal to any of the Search values provided.
If you do not provide a Default value, and the expression is not equal to any of the search values provided, then NULL is returned. The type of data (date/number/character) of the first result must match the results of all the other values, otherwise you may get oracle errors.
Example:
DECODE(~,1000,'Alpha',2000,'Bravo','Charlie') will evaluate the variable passed and compare it to the numbers 1000 (return Alpha) or 2000 (return Bravo) and if neither of these values will return Charlie. In programming terms this would look like:
IF ~ = 1000 THEN return ‘Alpha’ ELSEIF ~ = 2000 THEN return ‘Bravo’ ELSE return ‘Charlie’Without the last parameter (Charlie), the ELSE condition at the end would return NULL.
Screen captures are meant to be indicative of the concept being presented and may not reflect the current screen design.
If you have any comments or questions please email the Wiki Editor
All content © High Line Corporation