CASE Statements and expressions Flashcards
The Oracle/PLSQL CASE statement has the functionality of an ____
IF-THEN-ELSE statement
What types of datatypes can a case statement return?
Any type
Can different cases in a case statement return different datatypes?
No, all results must be the same datatype
What will the case statment return if all of the conditions are false and there is no else clause?
NULL
What are the 2 types of case statements?
- Simple CASE statement
- Searched CASE statement
What does a simple CASE statement do?
Evaluates a single expression
Compares the result with some values
What is the syntax for a simple CASE statement?
CASE selector WHEN selector_value_1 THEN statements_1 WHEN selector_value_1 THEN statement_2 ... ELSE else_statements END CASE;
PL/SQL will implicitly use if you do not provide an else clause?
ELSE
RAISE CASE_NOT_FOUND;
What does a searched CASE statement do?
Evaluates multiple Boolean expressions
Executes the sequence of statements associated with the first condition that evaluates to TRUE
What is the syntax for a searched CASE statement?
CASE WHEN condition_1 THEN statements_1 WHEN condition_2 THEN statements_2 ... WHEN condition_n THEN statements_n [ ELSE else_statements ] END CASE;]
In a searched CASE statement what order are the conditions in the WHEN clauses evaluated?
Top to bottom
In a searched CASE statement which condition fires if there are multiple WHEN clause whose condition evaluates to true?
The first one
What is a CASE expression?
A CASE expression evaluates a list of conditions and returns one of multiple possible result expressions