How to convert column value to CamelCase with Oracle?

Ayyoudy picture Ayyoudy · Sep 4, 2012 · Viewed 35.6k times · Source

I need a way to convert a column value to CamelCase with Oracle 10g. I prefer to do it in-line with my select statement but if I have to use a function, that is OK too.

I don't need to support underscores, just spaces.

Thanks

Answer

Ben picture Ben · Sep 4, 2012

I guess a combination of initcap() and replace() would work:

select replace(initcap('hi ben'),' ') from dual;

REPLA
-----
HiBen

This simply capitalises the first character of every word and then replaces the spaces with nothing.

It obviously won't work if the first character is numeric:

select replace(initcap('go 2stack overflow'),' ') from dual;

REPLACE(INITCAP(
----------------
Go2stackOverflow