SQL Case Expression
1. What is the purpose of the CASE expression in Oracle SQL?
A) To perform arithmetic operations
B) To manipulate strings
C) To make decisions based on conditions
D) To retrieve data from multiple tables
2. What will be the result of the following Oracle SQL CASE expression?
CASE
WHEN salary > 50000 THEN 'High'
WHEN salary BETWEEN 30000 AND 50000 THEN 'Medium'
ELSE 'Low'
END
If the salary is 40000?
A) High
B) Medium
C) Low
D) Error
3. What is the default return value of an Oracle SQL CASE expression if no conditions are met?
A) NULL
B) 0
C) ''
D) Depends on the data type
4. How many WHEN clauses can be used in a single Oracle SQL CASE expression?
A) Only 1
B) Up to 5
C) Up to 10
D) Unlimited
5. Which of the following is a valid Oracle SQL CASE expression?
A) CASE WHEN name = 'John' THEN 1 ELSE 0 END
B) CASE name = 'John' THEN 1 ELSE 0 END
C) CASE IF name = 'John' THEN 1 ELSE 0 END
D) CASE name = 'John' 1 ELSE 0 END
6. How many ELSE clauses can be used in a single Oracle SQL CASE expression?
A) Only 1
B) Up to 5
C) Up to 10
D) Unlimited
7. What is the purpose of the ELSE clause in an Oracle SQL CASE expression?
A) To specify a default value if no conditions are met
B) To specify a default value if all conditions are met
C) To exit the CASE expression
D) To start a new CASE expression
8. What will be the result of the following Oracle SQL CASE expression?
CASE
WHEN department = 'Sales' THEN 'High'
WHEN department = 'Marketing' THEN 'Medium'
WHEN department = 'IT' THEN 'Low'
END
If the department is 'HR'?
A) High
B) Medium
C) Low
D) NULL
9. Can a Oracle SQL CASE expression be used in a WHERE clause?
A) Yes
B) No
C) Only in a subquery
D) Only in a JOIN condition
10. What is the purpose of the CASE expression in Oracle SQL?
A) To perform arithmetic operations
B) To manipulate strings
C) To make decisions based on conditions
D) To retrieve data from multiple tables
Answers