Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Oracle query

Posted on 2011-09-06
5
Medium Priority
?
294 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
[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
  • 4
5 Comments
 
LVL 74

Expert Comment

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

0
 
LVL 74

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 74

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 74

Accepted Solution

by:
sdstuber earned 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

721 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