Home » SQL & PL/SQL » SQL & PL/SQL » Need a query
Need a query [message #189889] Mon, 28 August 2006 06:13 Go to next message
Messages: 5
Registered: February 2005
Junior Member
Hi friends,

I need a query to display the name "Devanand Santhosh Rao" as D.S.Rao.

Please help me.
Re: Need a query [message #189892 is a reply to message #189889] Mon, 28 August 2006 06:32 Go to previous messageGo to next message
Messages: 129
Registered: July 2006
Location: Westborough, MA
Senior Member
select substr('Devanand Santhosh Rao',1,1)||'.'||substr('Devanand Santhosh Rao',instr('Devanand Santhosh Rao',' ',1,1)+1,1)||'.'||substr('Devanand Santhosh Rao',instr('Devanand Santhosh Rao',' ',1,2)+1) from dual;

PS: this query not generic one. it will produce accurate result if you have given three word, otherwise not. so change accordingly for requirement

Re: Need a query [message #189897 is a reply to message #189889] Mon, 28 August 2006 07:06 Go to previous message
Messages: 2794
Registered: April 2006
Senior Member
SQL> select translate(substr(name,1,instr(name,' ',-1)),' abcdefghijklmnopqrstuvwxyz','.') ||
	substr(name,instr(name,' ',-1)+1) "Name" from (
	select 'Devanand Santhosh Rao' name from dual);

Previous Topic: update if exists else insert
Next Topic: Question about cursors (merged)
Goto Forum:

Current Time: Sun Oct 23 18:54:24 CDT 2016

Total time taken to generate the page: 0.10337 seconds