Oracle SQL - splitting Full Name separated by comma into First Name and Last Name

0
=
0
+
0
No specific Bitcoin Bounty has been announced by author. Still, anyone could send Bitcoin Tips to those who provide a good answer.
0

How to parse Full Name separated by comma into First Name and Last Name in Oracle SQL? For example, the following string 'Smith, James' should be split into 2 strings 'Smith' and 'James'

Tags: ,

1 Answer

1
=
0
=
$0
Internet users could send Bitcoin Tips to you if they like your answer!

Here you go, it works and does not throw exceptions even at the edge cases

select full_name,
       TRIM(SUBSTR(full_name, INSTR(full_name,',')+1, LENGTH(full_name))) first_name,
       TRIM(SUBSTR(full_name,1, INSTR(full_name,',')-1)) last_name
from 
(
select 'Smith, Michael' as full_name from dual union all
select 'Smith ,Michael' as full_name from dual union all
select 'Smith , Michael' as full_name from dual union all
select 'Lopes, Jennifer' as full_name from dual union all
select 'Lopes, Jennifer' as full_name from dual union all
select 'Lopes Jennifer' as full_name from dual union all
select 'Lopes' as full_name from dual union all
select 'Jlo,' as full_name from dual union all
select ',Jlo' as full_name from dual union all
select '' as full_name from dual 
)

Results:

enter image description here

SEND BITCOIN TIPS
0

Too many commands? Learning new syntax?

FavScripts.com is a free tool to save your favorite scripts and commands, then quickly find and copy-paste your commands with just few clicks.

Boost your productivity with FavScripts.com!

Post Answer