Home » SQL & PL/SQL » SQL & PL/SQL » Need help in query
Need help in query [message #235308] Fri, 04 May 2007 18:44 Go to next message
grk28
Messages: 38
Registered: June 2006
Member
Hi fnrds,

I have a typical requirement which is as follows..

My data is as follows

Id Name
1 JOHN
2 wenDy
3 wendy

My output should be as follows

Id Name
1 John
2 WenDy
3 Wendy

i.e i need to display the name with initial cap irrespective of remaining letters case and if all are in upper case then they need to convert into the lower case.The requirements seems to be strange ..

i have acheived 2& 3 by using
initcap(substr(name,1,1))||substr(name,2)

but i am stuck in converting the first record to John.

Is there any way to get that as well..

Immediate help would be appreciated.

Thanks in Advance
Re: Need help in query [message #235311 is a reply to message #235308] Fri, 04 May 2007 19:45 Go to previous messageGo to next message
g-rz
Messages: 3
Registered: May 2007
Junior Member
Try this query

select decode(upper(substr(name,2)),substr(name,2),initcap(substr(name,1,1))||substr(lower(name),2),initcap(substr(name,1,1))||substr(name,2 )) as name


I inserted a 4th row with jOHN, i think the result must be John and the query does it.

ORIGINAL NAME
-------- ----
JOHN John
wenDy WenDy
wendy Wendy
jOHN John

Re: Need help in query [message #235319 is a reply to message #235308] Fri, 04 May 2007 23:30 Go to previous message
grk28
Messages: 38
Registered: June 2006
Member
Thanks g-rz Smile it worked for me too ..
Previous Topic: Row Locks and Physical blocks
Next Topic: select query..
Goto Forum:
  


Current Time: Sat Dec 07 02:30:41 CST 2024