Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dynamic splitting of strings

854796Oct 25 2015 — edited Oct 25 2015

Hi,

I am trying to split the words in a string based on the space in the strings.

If the length of any CUST_NAME is greater than 27, I have to fetch it in my first part of the query and the remaining part in my second part of the query using SUBSTR and INSTR combination, as there is a In house tool which accepts these two functions only.

Below is the sample source data

Create Table S_Customer (

CUST_NAME VARCHAR2(100) ) ;

Insert into S_CUSTOMER VALUES('ABM Industries Incorporated') ;

Insert into S_CUSTOMER VALUES('Ace Hardware Corporation') ;

Insert into S_CUSTOMER VALUES('Adelphia Communications Corporation') ;

Insert into S_CUSTOMER VALUES('Apartment Investment and Management Company') ;

Insert into S_CUSTOMER VALUES('American Axle & Manufacturing Holdings, Inc') ;

Insert into S_CUSTOMER VALUES('Burlington Coat Factory Warehouse Corporation') ;

Insert into S_CUSTOMER VALUES('Apartment Investment and Management Company') ;

Insert into S_CUSTOMER VALUES('ABC') ;

COMMIT ;

I am expecting the first part and second part as below.since there is no way of logically splitting the records I am taking the space for logically splitting of records.

    

Length of the valueCustomer NameFirst PartSecond Part
27ABM Industries IncorporatedABM Industries Incorporated
24Ace Hardware CorporationAce Hardware Corporation
35Adelphia Communications CorporationAdelphia CommunicationsCorporation
43Apartment Investment and Management CompanyApartment Investment and Management Company
43American Axle & Manufacturing Holdings, IncAmerican Axle & Manufacturing Holdings, Inc
45Burlington Coat Factory Warehouse CorporationBurlington Coat Factory Warehouse Corporation
27Apartment Investment and MaApartment Investment and Management Company

I tried using the below functions but the out put is not coming as expected, please suggest how can I achieve this.

For the First Part  SUBSTR( CUST_NAME, 1, INSTR(CUST_ID, ' ' )-1 )

For the Last Part SUBSTR( CUST_NAME, INSTR(CUST_ID, ' ')+1 )

Regards,

Deepti

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 22 2015
Added on Oct 25 2015
2 comments
406 views