Solved

Extracting Subsrings in columns

Posted on 2013-12-04
2
323 Views
Last Modified: 2013-12-04
I need to extract first name as one field and last name as another field from a column in a table that stores the whole name as 'last name, first name mi'.  For example, I need the following results:

from:  'Doe, Jane L'
         'Smith Jr., Frank C'
         'Brown M.D., Lawrence'

I need two columns in my SQL result set:
First Name             Last Name
Jane                         Doe
Frank                       Smith Jr.
Lawrence                Brown M.D.


Thank You!
0
Comment
Question by:PattiN
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 39696647
Try this:

drop table tab1 purge;
create table tab1(name varchar2(50));

insert into tab1 values('Doe, Jane L');
insert into tab1 values('Smith Jr., Frank C');
insert into tab1 values('Brown M.D., Lawrence');
commit;

select
	substr(regexp_substr(name,', [^ ]+'),3),
	regexp_substr(name,'^[^,]+')
from tab1;

Open in new window

0
 

Author Closing Comment

by:PattiN
ID: 39696758
PERFECT!  Thank you so much.

Merry Christmas!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question