Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to delete a space and the string after space, in a entire column ?

Posted on 2013-05-23
4
Medium Priority
?
540 Views
Last Modified: 2013-05-23
Helo, could you help me with the next issue?

I need delete a first space and the string after their space, in a entire column

Example with just a row:

select pointname
from from_ap
where pointname like 'AER_4L_SA6____I%';

Open in new window

say:
AER_4L_SA6____I Corriente Sal.06 33kV

Open in new window

I want:
AER_4L_SA6____I

Open in new window

It is possible to do using SUBSTR, INSTR or regular expressions, in every column 'pointname'?

Thank in advanced!
0
Comment
Question by:carlino70
  • 2
4 Comments
 
LVL 78

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 1000 total points
ID: 39191010
You can do it with regular expressions but they are expensive.

Given something this simple I would go with:
substr(pointname,1,instr(pointname,' ')-1)
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39191015
If you are interested, here is the regex version:
regexp_substr(pointname,'^[^ ]*')
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 1000 total points
ID: 39191047
if you use the substr/instr method, you have to be sure there really is a space if so, then the first post will work.

if the string might not have a space in it and you'd like to return the entire string then either use the regexp_substr method  or


case when instr(pointname,' ') = 0 then pointname else substr(pointname,1,instr(pointname,' ')-1)  end

or slightly smaller syntax using decode

decode(instr(pointname,' ') ,0, pointname, substr(pointname,1,instr(pointname,' ')-1) )
0
 

Author Closing Comment

by:carlino70
ID: 39191531
It works.

Thanks to both!
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

824 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