Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert column value to CamelCase with Oracle?

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

like image 877
Ayyoudy Avatar asked Sep 04 '12 14:09

Ayyoudy


People also ask

How to get Camel case in oracle?

select substr(lower('Camel Case means the first char should be lower cased'),1,1)||substr(replace(initcap('Camel Case means the first char should be lower cased'),' '),2) from dual; camelCaseMeansTheFirstCharShouldBeLowerCased 1 row selected. CamelCase could also be the first letter.

Can we use case in Oracle?

The CASE statement can be used in the following versions of Oracle/PLSQL: Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i.

Is like case-sensitive in Oracle?

The default behaviour of LIKE and the other comparison operators, = etc is case-sensitive.


2 Answers

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
like image 197
Ben Avatar answered Oct 10 '22 03:10

Ben


That's not my understanding of camelCase

select substr(lower('Camel Case means the first char should be lower cased'),1,1)||substr(replace(initcap('Camel Case means the first char should be lower cased'),' '),2) from dual;
camelCaseMeansTheFirstCharShouldBeLowerCased                                    
1 row selected.
like image 26
Dave the Humanoid Avatar answered Oct 10 '22 02:10

Dave the Humanoid