Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Sirisha.

Asked: July 28, 2017 - 4:25 pm UTC

Last updated: July 30, 2017 - 10:01 am UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi

I have a query regarding strings. If I give a string like 'Mrs xxxxxx yyyyy', I should get the output like

Title FirstName LastName
Mrs xxxxxx yyyyy

How can I do this using string functions.

Many Thanks
Sirisha

and Connor said...

SQL> with t as ( select  'Mrs xxxxxx yyyyy' str from dual )
  2  select
  3    substr(str,1,instr(str,' ')-1) title,
  4    substr(str,instr(str,' ')+1,instr(str,' ',1,2)-instr(str,' ',1,1)-1) forename,
  5    substr(str,instr(str,' ',1,2)+1) surname
  6  from t;

TIT FORENA SURNA
--- ------ -----
Mrs xxxxxx yyyyy


Is this answer out of date? If it is, please let us know via a Comment

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.