I’m curious which is better in these queries (performance or anything).
SELECT some_column,
CASE case_column
WHEN 1 THEN 'a'
WHEN 2 THEN 'a'
WHEN 3 THEN 'a'
WHEN 5 THEN 'b'
WHEN 6 THEN 'b'
...
END AS case_column_str
FROM some_table ORDER BY case_column_str
or
SELECT some_column,
CASE
WHEN case_column=1 OR case_column=2 OR case_column=3 THEN 'a'
WHEN case_column=5 OR case_column=6 THEN 'b'
...
END AS case_column_str
FROM some_table ORDER BY case_column_str
Does either of these queries have advantages over the other? Are there any significant differences between the two except for the second being able to use other field for more filtering? What if I’m just going to filter a single column?
Any decent optimizer will treat the two as essentially identical; it is very unlikely you’ll be able to measure the difference in performance. Oracle has a decent enough optimizer that you’ll be hard-pressed to measure the difference at all. You could look at the query plans, but don’t be surprised if they’re identical.