Avatar of shieldsco
shieldscoFlag for United States of America

asked on 

Orace SQL remove all characters after second space

How do I remove all characters after second space. For example :
Smith, Joe A = Smith, Joe
Smith, Joe A. = Smith, Joe
* Oracle PL/SQLSQL

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)
Avatar of arnold
arnold
Flag of United States of America image

Not an oracle, but see if the below helps

Have a look at instr to locate the second space.
http://www.sqlines.com/oracle/functions/instr

Then use substr to cut the string using the second position of space from instr -1
To cut the string

The -1 might not be necessary.
Avatar of Peter Chan
Peter Chan
Flag of Hong Kong image

Try
Declare
  v_str varchar2(30);
  V_p0 integer;
  V_p1 integer;
begin
  v_str:='Smith, Joe A';
  v_p0:=instr(v_str,' ');
  v_p1:=instr(v_str,' ',v_p0+1);
  dbms_output.put_line(substr(v_str,1,v_p1-1));
end;
/

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SQL
SQL

SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.

61K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo