Q1
True / FalseThe CASE statement in Oracle is used to perform conditional logic in SQL queries.
The CASE statement allows for conditional logic within SQL queries, similar to if-else statements in programming languages.
Q2
True / FalseIn Oracle, the CASE statement must always include an ELSE clause.
The ELSE clause is optional in a CASE statement. If no ELSE clause is provided and no conditions are met, the CASE statement returns NULL.
Q3
True / FalseThe CASE statement in Oracle can be used in both SELECT and UPDATE statements.
The CASE statement can be used in SELECT, UPDATE, and other SQL statements to provide conditional logic.
Q4
True / FalseIn Oracle, the CASE statement can only evaluate equality conditions.
The CASE statement can evaluate a variety of conditions, including equality, inequality, and other comparisons.
Q5
True / FalseThe CASE statement in Oracle can be nested within another CASE statement.
CASE statements can be nested to handle complex conditional logic within SQL queries.
Q6
True / FalseIn Oracle, the CASE statement can include aggregate functions within its conditions.
Aggregate functions can be used within CASE statement conditions to evaluate based on aggregated data.
Q7
True / FalseIn Oracle, the CASE statement can be used in the ORDER BY clause to sort results conditionally.
The CASE statement can be used in the ORDER BY clause to apply conditional sorting to the result set.
Q8
True / FalseThe CASE statement in Oracle can be used to return different data types based on conditions.
All return values in a CASE statement must be of the same data type or compatible types to avoid data type errors.
Q9
True / FalseIn Oracle, performance of queries with CASE statements can be optimized using indexes and careful query design.
Proper indexing and query optimization can help improve the performance of queries that use CASE statements.
Q10
True / FalseThe Oracle Certified Professional (OCP) exam includes knowledge on using the CASE statement effectively, understanding its syntax, and optimizing its performance in SQL queries.
The OCP certification covers advanced topics, including the effective use of the CASE statement, understanding its syntax, and optimizing its performance in SQL queries.
Q21
Multiple ChoiceWhich SQL code snippet demonstrates a basic use of the CASE statement to categorize employees based on their salary in Oracle?
SQL Code
SELECT employee_id, salary,
CASE
WHEN salary > 50000 THEN 'High'
WHEN salary BETWEEN 30000 AND 50000 THEN 'Medium'
ELSE 'Low'
END AS salary_category
FROM employees;
SELECT employee_id, salary,
CASE
WHEN salary > 60000 THEN 'High'
WHEN salary BETWEEN 30000 AND 60000 THEN 'Medium'
ELSE 'Low'
END AS salary_category
FROM employees;
Options A and B correctly use the CASE statement to categorize employees based on their salary. Option C is incorrect because it categorizes incorrectly, and Option D is incorrect as it does not use the CASE statement.
Q22
Multiple ChoiceWhich SQL code snippet uses the CASE statement to handle NULL values in Oracle?
SQL Code
SELECT employee_id,
CASE
WHEN manager_id IS NULL THEN 'No Manager'
ELSE manager_id
END AS manager_status
FROM employees;
SELECT employee_id,
CASE
WHEN commission_pct IS NULL THEN 'No Commission'
ELSE TO_CHAR(commission_pct * 100) || '%'
END AS commission_status
FROM employees;
SELECT employee_id,
CASE
WHEN hire_date IS NULL THEN 'Hire Date Unknown'
ELSE TO_CHAR(hire_date, 'MM/DD/YYYY')
END AS hire_date_status
FROM employees;
Options A, B, and C correctly use the CASE statement to handle NULL values in different contexts. Option D is incorrect because it does not handle NULL values using the CASE statement.
Q27
Multiple ChoiceWhich SQL code snippet demonstrates the use of the CASE statement to create a calculated column for a report in Oracle?
SQL Code
SELECT employee_id, salary,
CASE
WHEN salary > 50000 THEN salary * 1.1
ELSE salary * 1.05
END AS adjusted_salary
FROM employees;
SELECT department_id, salary,
CASE
WHEN department_id = 10 THEN salary * 1.2
ELSE salary * 1.1
END AS department_adjusted_salary
FROM employees;
Options A and B correctly use the CASE statement to create a calculated column for a report. Option C is incorrect because it does not provide a complete calculation, and Option D is incorrect as it does not use the CASE statement for a calculated column.
Q30
Multiple ChoiceWhich SQL code snippet demonstrates the use of the CASE statement to create a summary report with conditional logic applied to aggregated data in Oracle?
SQL Code
SELECT department_id, COUNT(employee_id) AS num_employees,
CASE
WHEN AVG(salary) > 60000 THEN 'High Average Salary'
ELSE 'Moderate Average Salary'
END AS salary_status
FROM employees
GROUP BY department_id;
SELECT region, SUM(sales_amount) AS total_sales,
CASE
WHEN SUM(sales_amount) > 100000 THEN 'High Revenue Region'
ELSE 'Moderate Revenue Region'
END AS revenue_status
FROM sales
GROUP BY region;
Options A and B correctly use the CASE statement to create a summary report with conditional logic applied to aggregated data. Option C is incorrect because it does not group by the necessary columns, and Option D is incorrect as it does not use the CASE statement for the summary report.