Case When Else in Oracle SQL
Case When Else in Oracle SQL
228
17-Jul-2023
Aryan Kumar
18-Jul-2023The CASE WHEN ELSE statement in Oracle SQL is a conditional statement that allows you to evaluate a condition and return a different result depending on the outcome of the evaluation. The CASE WHEN ELSE statement is a powerful tool that you can use to perform complex conditional logic in your SQL queries.
The syntax for the CASE WHEN ELSE statement is as follows:
SQL
The
condition1,condition2, etc., are expressions that can be evaluated to a Boolean value. Theresult1,result2, etc., are the results that will be returned if the corresponding condition evaluates toTRUE. Thedefault_resultis the result that will be returned if none of the conditions evaluate toTRUE.For example, the following CASE WHEN ELSE statement will return the grade of a student based on their score:
SQL
If the student's score is greater than or equal to 90, then the CASE WHEN ELSE statement will return the letter grade
A. If the student's score is greater than or equal to 80, but less than 90, then the CASE WHEN ELSE statement will return the letter gradeB. And so on. If the student's score is less than 60, then the CASE WHEN ELSE statement will return the letter gradeF.The CASE WHEN ELSE statement is a powerful tool that you can use to perform complex conditional logic in your SQL queries. By using the CASE WHEN ELSE statement, you can write more concise and readable queries that are easier to understand and maintain.