Hans Baum Hans Baum - 6 months ago 13
SQL Question

First letter alone in Upper Case Oracle SQL



I am trying out to make the first letter alone in Upper case.


select case
when 'G' then 'GERMANY'
when 'US' then 'AMERICA'
when 'S' then 'SPAIN
else 'unknown'
from customer


Oracle output:

GERMANY

AMERICA
SPAIN



my not working 'solution'

select case initcap(land)
when 'G' then 'GERMANY'
when 'US' then 'AMERICA'
when 'S' then 'SPAIN
else 'unknown'
from customer


Oracle output:

GERMANY

AMERICA
SPAIN


Answer

Since everyone has to make assumptions about what you need, here is my attempt at understanding what you are looking for -

SELECT INITCAP (
          CASE land
             WHEN 'G' THEN 'GERMANY'
             WHEN 'US' THEN 'AMERICA'
             WHEN 'S' THEN 'SPAIN'
             ELSE 'unknown'
          END)
  FROM customer;

I would however argue that unless you have some sort of way to auto-generate these case statements (which I doubt), why not just write WHEN 'G' THEN 'Germany' in the first place.

Comments