๐ Using CASE Statements in Oracle SQL for Conditional Logic

As part of my continued learning with Oracle Autonomous Database, I explored how to use CASE statements in SQL. CASE statements allow us to apply conditional logic directly within queries, making data more meaningful.
๐ฏ Objective
The goal of this activity was to:
Understand how CASE statements work
Apply conditional logic in SQL queries
Categorize data dynamically
๐ป Step 1: Creating the Table
CREATE TABLE employees (
emp_id NUMBER,
emp_name VARCHAR2(50),
salary NUMBER
);
๐งช Step 2: Inserting Data
INSERT INTO employees VALUES (1, 'Ali', 50000);
INSERT INTO employees VALUES (2, 'Ahmed', 70000);
INSERT INTO employees VALUES (3, 'Sara', 60000);
INSERT INTO employees VALUES (4, 'Zara', 65000);
๐ Step 3: Using CASE Statement
SELECT emp_name, salary,
CASE
WHEN salary >= 65000 THEN 'High Salary'
WHEN salary >= 55000 THEN 'Medium Salary'
ELSE 'Low Salary'
END AS salary_category
FROM employees;
This query categorizes employees based on their salary.
๐ก What I Learned
How to use CASE for conditional logic
Categorizing data dynamically
Writing smarter SQL queries
๐ Conclusion
This activity helped me understand how SQL can be used not only for retrieving data but also for applying logic and generating meaningful insights.




