Solved

Oracle query

Posted on 2011-09-06
5
287 Views
Last Modified: 2012-08-13
I've this table: TAB_USERS with column USER (name last + first name)

USER
Smith John
Smith David
Smith Jack
Di Martino Giovanni
De Nicola Antonio

I'd like to write a query with only upper (first name).

I tried this query:

select UPPER(substr (USER, instr(USER, ' ')+1))
from TAB_USERS;

But I've some problem with the names: Di Martino Giovanni and De Nicola Antonio

How can I write my query also considering the names with two spaces?

I'd like to get this output:

USER
JOHN
DAVID
JACK
GIOVANNI
ANTONIO
0
Comment
Question by:ralph_rea
  • 4
5 Comments
 
LVL 73

Expert Comment

by:sdstuber
ID: 36488823
select UPPER(regexp_substr(USER, '[^ ]+$')) from TAB_USERS;

0
 
LVL 73

Expert Comment

by:sdstuber
ID: 36488830
select UPPER(substr (USER, instr(USER, ' ',-1)+1))
from TAB_USERS;

0
 

Author Comment

by:ralph_rea
ID: 36488855
Ok, thanks bu now I've another problem, there are some users with this name: Smith John (USA)

How Can I avoid this problem??
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 36488896
>> now I've another problem


select UPPER(regexp_substr(replace(USER,'(USA)'), '[^ ]$')) from TAB_USERS;


if you need something more sophisticated than that...

please open a new question,  list all the special parsing rules you want and how to identify them
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 36489409
sorry,  I missed some characters above...

 UPPER(regexp_substr(replace(usr,' (USA)'), '[^ ]+$'))

or, using the instr method...

UPPER(SUBSTR(REPLACE(usr, ' (USA)'), INSTR(REPLACE(usr, ' (USA)'), ' ', -1) + 1))
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to recover a database from a user managed backup
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now