Home » SQL & PL/SQL » SQL & PL/SQL » how to remove dots in the column
how to remove dots in the column [message #615916] Wed, 11 June 2014 03:35 Go to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi all,

select instructions from oe_order_headers_all
where order_number=1234

Mary Lesicko.5025 Southridge Park [b]Dr..Saint[/b] Louis.MO.63129..

And i need to dispaly as below

Mary Lesicko.5025 Southridge Park [b]Dr.Saint[/b] Louis.MO.63129..
Re: how to remove dots in the column [message #615920 is a reply to message #615916] Wed, 11 June 2014 03:57 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Do you need the last two dots? If not then simply use replace :

SQL> WITH DATA AS(
  2  SELECT 'Mary Lesicko.5025 Southridge Park [b]Dr..Saint[/b] Louis.MO.63129..' str FROM dual
  3  )
  4  SELECT REPLACE(str, '..','.') col FROM DATA;
COL
-----------------------------------------------------------------
Mary Lesicko.5025 Southridge Park [b]Dr.Saint[/b] Louis.MO.63129.
Re: how to remove dots in the column [message #615921 is a reply to message #615920] Wed, 11 June 2014 04:04 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Or, if you are sure that there would be only one instance of '..' dots in between the string, and you want to keep the last two dots, then use SUBSTR :

SQL> WITH DATA AS(
  2  SELECT 'Mary Lesicko.5025 Southridge Park [b]Dr..Saint[/b] Louis.MO.63129..' str FROM dual
  3  )
  4  SELECT SUBSTR(STR, 1, INSTR(STR, '..', 1) - 1) ||
  5         SUBSTR(STR, INSTR(STR, '..', 1) + 1) col
  6    FROM DATA;
COL
------------------------------------------------------------------
Mary Lesicko.5025 Southridge Park [b]Dr.Saint[/b] Louis.MO.63129..
Re: how to remove dots in the column [message #615926 is a reply to message #615921] Wed, 11 June 2014 04:32 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Thanks Lalit.. Smile

I need to display only CITY from that column and i tried to retrieve only city name

Mary Lesicko.5025 Southridge Park Dr.Saint Louis.MO.63129..

SELECT Substr (instructions, Instr (instructions, '.', 1, 2) + 1, (( Instr (instructions, '.', 1, 3) - 1 ) - Instr (instructions, '.', 1, 2) ))
FROM   oe_order_headers_all 
WHERE  order_number = 1234 

But i am getting NULL values , means no rows return.

I need only Saint Louis that is CITY .
Re: how to remove dots in the column [message #615928 is a reply to message #615926] Wed, 11 June 2014 04:38 Go to previous messageGo to next message
cookiemonster
Messages: 13919
Registered: September 2008
Location: Rainy Manchester
Senior Member
Null values is not the same as no rows, they are different things and it's doing one or the other.
Looks like the substr works:
SQL> WITH oe_order_headers_all AS (SELECT 'Mary Lesicko.5025 Southridge Park Dr.Saint Louis.MO.63129..' instructions,
  2                                1234 AS order_number FROM dual)
  3  SELECT Substr (instructions, Instr (instructions, '.', 1, 2) + 1, (( Instr (instructions, '.', 1, 3) - 1 ) - Instr (instructions, '.', 1, 2) ))
  4  FROM   oe_order_headers_all
  5  WHERE  order_number = 1234
  6  /
 
SUBSTR(INSTRUCTIONS,INSTR(INST
------------------------------
Saint Louis
 

So it looks like the problem is that no rows match the where clause.
Re: how to remove dots in the column [message #615930 is a reply to message #615928] Wed, 11 June 2014 04:44 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
WITH oe_order_headers_all AS (SELECT 'Mary Lesicko.5025 Southridge Park Dr..Saint Louis.MO.63129..' instructions,
                                  1234 AS order_number FROM dual)
    SELECT Substr (instructions, Instr (instructions, '.', 1, 2) + 1, (( Instr (instructions, '.', 1, 3) - 1 ) - Instr (instructions, '.', 1, 2) ))
    FROM   oe_order_headers_all
    WHERE  order_number = 1234


Thanks cookiemonster, could you please run the same query please. I am getting no rows
Re: how to remove dots in the column [message #615931 is a reply to message #615930] Wed, 11 June 2014 04:51 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi cookiemonster, you are taken

SELECT 'Mary Lesicko.5025 Southridge Park Dr.Saint Louis.MO.63129..'

but in my table my column had

Mary Lesicko.5025 Southridge Park Dr..Saint Louis.MO.63129..

Please help me
Re: how to remove dots in the column [message #615933 is a reply to message #615930] Wed, 11 June 2014 05:13 Go to previous messageGo to next message
cookiemonster
Messages: 13919
Registered: September 2008
Location: Rainy Manchester
Senior Member
mist598 wrote on Wed, 11 June 2014 10:44

Thanks cookiemonster, could you please run the same query please. I am getting no rows


You are getting a row, with a value of null. Do not confuse that with no rows, they are different problems that require different solutions.
Add each instr separately to the select and check they give the values you expect.
Re: how to remove dots in the column [message #615935 is a reply to message #615933] Wed, 11 June 2014 05:31 Go to previous messageGo to next message
cookiemonster
Messages: 13919
Registered: September 2008
Location: Rainy Manchester
Senior Member
What is between the 2nd and 3rd dot in this string:
'Mary Lesicko.5025 Southridge Park Dr..Saint Louis.MO.63129..'
Re: how to remove dots in the column [message #615937 is a reply to message #615926] Wed, 11 June 2014 05:37 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
I need to display only CITY from that column and i tried to retrieve only city name


How do you know where is the city in your data?

Re: how to remove dots in the column [message #615940 is a reply to message #615937] Wed, 11 June 2014 05:50 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
How do you know where is the city in your data?

Hi Michel,

Mary America(1).1234 Southridge Park Dr.(2).Samna Lorie(3).MO(4).31234(5)..  -->Samna Lorie

Paula Julian(1).363 Revere Beach BLVD(2).Revere(3).MA(4).02151(5)..-->Revere

In the above outputs in the first one 3rd one is the City  & second one same 3rd on is the City
Re: how to remove dots in the column [message #615941 is a reply to message #615940] Wed, 11 June 2014 05:58 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
In the above outputs in the first one 3rd one is the City & second one same 3rd on is the City


I don't understand what this mean.

Does the data you posted actual ones? I mean, is the city always followed by '(3)'?

[Updated on: Wed, 11 June 2014 05:59]

Report message to a moderator

Re: how to remove dots in the column [message #615943 is a reply to message #615941] Wed, 11 June 2014 06:03 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
Does the data you posted actual ones? I mean, is the city always followed by '(3)'?


Yes Michel
Re: how to remove dots in the column [message #615945 is a reply to message #615943] Wed, 11 June 2014 06:07 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

So if it is between '(2).' and '(3)':
SQL> col val format a80
SQL> col city format a15
SQL> with
  2    data as (
  3      select 'Mary America(1).1234 Southridge Park Dr.(2).Samna Lorie(3).MO(4).31234(5)..'  val from dual
  4      union all
  5      select 'Paula Julian(1).363 Revere Beach BLVD(2).Revere(3).MA(4).02151(5)..' from dual
  6    )
  7  select val,
  8         substr(val,
  9                instr(val, '(2).')+4,
 10                instr(val,'(3)')-instr(val, '(2).')-4
 11               ) city
 12  from data
 13  /
VAL                                                                              CITY
-------------------------------------------------------------------------------- ---------------
Mary America(1).1234 Southridge Park Dr.(2).Samna Lorie(3).MO(4).31234(5)..      Samna Lorie
Paula Julian(1).363 Revere Beach BLVD(2).Revere(3).MA(4).02151(5)..              Revere

Re: how to remove dots in the column [message #615948 is a reply to message #615940] Wed, 11 June 2014 06:15 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
mist598 wrote on Wed, 11 June 2014 16:20
How do you know where is the city in your data?

Hi Michel,

Mary America(1).1234 Southridge Park Dr.(2).Samna Lorie(3).MO(4).31234(5)..  -->Samna Lorie

Paula Julian(1).363 Revere Beach BLVD(2).Revere(3).MA(4).02151(5)..-->Revere

In the above outputs in the first one 3rd one is the City  & second one same 3rd on is the City


SQL> WITH data
  2       AS (SELECT
  3  'Mary America(1).1234 Southridge Park Dr.(2).Samna Lorie(3).MO(4).31234(5)..'
  4          str
  5   FROM   dual
  6   UNION ALL --Samna Lorie
  7   SELECT 'Paula Julian(1).363 Revere Beach BLVD(2).Revere(3).MA(4).02151(5)..'
  8   FROM   dual)--Revere
  9  SELECT Substr(str, Instr(str, '(2).', 1) + 4, Instr(str, '(3).', 1) -
 10                                                       Instr(str, '(2).', 1) - 4)
 11         str
 12  FROM   data;
STR
---------------------------------------------------------------------------
Samna Lorie
Revere


Edit -- Didn't see Michel already replied

The original question was to remove the extra dots, then in the course the question got changed to get a part of string.

[Updated on: Wed, 11 June 2014 06:30]

Report message to a moderator

Re: how to remove dots in the column [message #615949 is a reply to message #615948] Wed, 11 June 2014 06:39 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Christine Bast-Friesen.200 E. Carrington Lane.Appleton.WI.54913..
 
Required output is '200 E. Carrington Lane'
 
Actual out out is 'Carrington Lane'
Re: how to remove dots in the column [message #615950 is a reply to message #615949] Wed, 11 June 2014 06:44 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Why don't you try with all the solutions provided above?
Quote:
Christine Bast-Friesen.200 E. Carrington Lane.Appleton.WI.54913..

Required output is '200 E. Carrington Lane'

Actual out out is 'Carrington Lane'


Now what is the rule for this new requirement? The same has been suggested you here too https://community.oracle.com/thread/3571097

[Updated on: Wed, 11 June 2014 06:47]

Report message to a moderator

Re: how to remove dots in the column [message #615951 is a reply to message #615950] Wed, 11 June 2014 06:46 Go to previous messageGo to next message
cookiemonster
Messages: 13919
Registered: September 2008
Location: Rainy Manchester
Senior Member
So in this case you want everything between the 1st and 3rd dot. What rule do you use to determine which dots you need to use to define the start and end of the section you want?
Re: how to remove dots in the column [message #615952 is a reply to message #615949] Wed, 11 June 2014 06:54 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

What are the REAL data? There are no more (2) (3) and so on.
What do you ACTUALLY want from the data?
At each of your posts the data change and the output too.
How can you expect to write a query if you don't know what you have and don't know what you want?
You are wasting everyone's time in SEVERAL forums!


Re: how to remove dots in the column [message #615953 is a reply to message #615950] Wed, 11 June 2014 06:56 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
Why don't you try with all the solutions provided above?


Yes it tried but i got for some columns only.
Quote:

So in this case you want everything between the 1st and 3rd dot. What rule do you use to determine which dots you need to use to define the start and end of the section you want?


1)the column shown about addresses of the company and it contains like state,city,district,country..

I checked in the columns it contains address9state,city,district,country.)

As "Christine Bast-Friesen.200 E. Carrington Lane.Appleton.WI.54913.."

Required output is '200 E. Carrington Lane' is the city
Thanks
Re: how to remove dots in the column [message #615954 is a reply to message #615953] Wed, 11 June 2014 07:01 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Is CITY always between 1st and 3rd dot?

[Updated on: Wed, 11 June 2014 07:01]

Report message to a moderator

Re: how to remove dots in the column [message #615957 is a reply to message #615954] Wed, 11 June 2014 07:12 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member


SELECT instructions,
    REGEXP_SUBSTR(instructions,'[^\.]+',1,1) text1,
    REGEXP_SUBSTR(instructions,'[^\.]+',1,2) text2,
    REGEXP_SUBSTR(instructions,'[^\.]+',1,3) text3,
    REGEXP_SUBSTR(instructions,'[^\.]+',1,4) text4,
    REGEXP_SUBSTR(instructions,'[^\.]+',1,5) text5
FROM   oe_order_headers_all
WHERE order_number in (1234,1235,1236,1237,1238)


Christine Bast-Friesen(1).200 E. Carrington Lane(2).Appleton(3).WI(4).54913(5)..

In the above Appleton(3)is the city

text1 - ship_to_name
text2 - ship_to_address
text3 - city
text4 - state
text5 - zip

1)Christine Bast-Friesen text1
2)200 E. Carrington Lane  text2
3)Appleton (CITY)
4)WI
5)54913

I need the bove format, but i am getting the below format.
1)Christine Bast-Friesen
2)200 E
3) Carrington Lane
4)Appleton
5)WI

[Updated on: Wed, 11 June 2014 07:12]

Report message to a moderator

Re: how to remove dots in the column [message #615958 is a reply to message #615953] Wed, 11 June 2014 07:13 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
Required output is '200 E. Carrington Lane' is the city


For me the city is "Appleton".

Once again, what is the rule to get the city?

Re: how to remove dots in the column [message #615959 is a reply to message #615957] Wed, 11 June 2014 07:14 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
Christine Bast-Friesen(1).200 E. Carrington Lane(2).Appleton(3).WI(4).54913(5)..


Is there or not those (2), (3)...?
What is the ACTUAL data?

Re: how to remove dots in the column [message #615960 is a reply to message #615957] Wed, 11 June 2014 07:15 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
3)Appleton (CITY)

Quote:
Required output is '200 E. Carrington Lane' is the city


What do you want, in the end?

Re: how to remove dots in the column [message #615965 is a reply to message #615958] Wed, 11 June 2014 07:26 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
Once again, what is the rule to get the city?


In the table in the instructions column -->ship_to_name.ship_to_addres.city.state.zip

Christine Bast-Friesen(ship_to_name).200 E. Carrington Lane(ship_to_addres).Appleton(city).WI(sate).54913(zip)..

In the column all the 5 addresses denoted by dot so, it takes the below column
Christine Bast-Friesen.200 E. Carrington Lane.Appleton.WI.54913..

as

Christine Bast-Friesen(ship_to_name).200 E(ship_to_addres). Carrington Lane(city).Appleton(sate).WI(zip).

I need to display the below format
Christine Bast-Friesen(ship_to_name).200 E. Carrington Lane(ship_to_addres).Appleton(city).WI(sate).54913(zip)..

not need below  format
Christine Bast-Friesen(ship_to_name).200 E(ship_to_addres). Carrington Lane(city).Appleton(sate).WI(zip).

Re: how to remove dots in the column [message #615966 is a reply to message #615965] Wed, 11 June 2014 07:28 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

There are or there are not those (2) (3) ...?
You said there are and you post data where there not.

Re: how to remove dots in the column [message #615967 is a reply to message #615965] Wed, 11 June 2014 07:29 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Michel Cadot wrote on Wed, 11 June 2014 14:14

Quote:
Christine Bast-Friesen(1).200 E. Carrington Lane(2).Appleton(3).WI(4).54913(5)..


Is there or not those (2), (3)...?
What is the ACTUAL data?


Re: how to remove dots in the column [message #615968 is a reply to message #615916] Wed, 11 June 2014 07:29 Go to previous messageGo to next message
EdStevens
Messages: 1376
Registered: September 2013
Senior Member
As pointed up in your duplicate thread at OTN, this is a VERY bad design. And your difficulty in solving the problem is a textbook example of WHY it is a bad design. Until you correct the design by properly normalizing the data, you will continue to struggle with this issue. At some point, your organization is simply going to have to fix the root problem and redesign the table by separating the various components of this 'bit bucket column' into properly defined columns: LAST_NAME, FIRST_NAME, MIDDLE_NAME, STREET_ADDRESS, CITY, STATE, ZIP
Re: how to remove dots in the column [message #615969 is a reply to message #615957] Wed, 11 June 2014 07:30 Go to previous messageGo to next message
cookiemonster
Messages: 13919
Registered: September 2008
Location: Rainy Manchester
Senior Member
mist598 wrote on Wed, 11 June 2014 13:12

Christine Bast-Friesen(1).200 E. Carrington Lane(2).Appleton(3).WI(4).54913(5)..

In the above Appleton(3)is the city

In the above the (3) is in the wrong place. You can't stick numbers in to indicate dots and then skip some of the dots.
You might know instinctively from looking at that how to split it but you can't write code based on instinct. Code has to written based on definable rules and you haven't supplied any.
If you can't write out a set of rules that define at what points the string is to be split then no one can write code to do what you want.
You seem to want it to be split on some, but not all, of the dots. If so you need to define a set of rules that will allow us to determine which dots can be ignored for splitting.
Re: how to remove dots in the column [message #615973 is a reply to message #615965] Wed, 11 June 2014 07:34 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
mist598 wrote on Wed, 11 June 2014 17:56
I need to display the below format
Christine Bast-Friesen(ship_to_name).200 E. Carrington Lane(ship_to_addres).Appleton(city).WI(sate).54913(zip)..


For one last time, I hope this is what you want as ship_to_address :

SQL> WITH data
  2       AS (SELECT
  3       'Christine Bast-Friesen.200 E. Carrington Lane.Appleton.WI.54913..' str
  4           FROM   dual)
  5  SELECT Substr(str, 1, Instr(str, '.', 1, 1) - 1)
  6         ship_to_name,
  7         Substr(str, Instr(str, '.', 1, 1) + 1, Instr(str, '.', 1, 3) -
  8                                                Instr(str, '.', 1, 1) - 1)
  9         ship_to_addres,
 10         Substr(str, Instr(str, '.', 1, 3) + 1, Instr(str, '.', 1, 4) -
 11                                                Instr(str, '.', 1, 3) - 1) city,
 12         Substr(str, Instr(str, '.', 1, 4) + 1, Instr(str, '.', 1, 5) -
 13                                                Instr(str, '.', 1, 4) - 1) state,
 14         Substr(str, Instr(str, '.', 1, 5) + 1, Instr(str, '.', 1, 6) -
 15                                                Instr(str, '.', 1, 5) - 1) zip
 16  FROM   data;
SHIP_TO_NAME           SHIP_TO_ADDRES         CITY     STATE ZIP
---------------------- ---------------------- -------- ----- -----
Christine Bast-Friesen 200 E. Carrington Lane Appleton WI    54913


Your biggest problem is that you do not follow normalization.

Edit : Update the code to suffice all the requirements together

[Updated on: Wed, 11 June 2014 07:43]

Report message to a moderator

Re: how to remove dots in the column [message #615975 is a reply to message #615926] Wed, 11 June 2014 07:40 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

If we can assume there is no dot in zip, state and city, then city can be found with:
SQL> col val format a70
SQL> col city format a15
SQL> with
  2    data as (
  3      select 'Mary America.1234 Southridge Park Dr..Samna Lorie.MO.31234..' val from dual
  4      union all
  5      select 'Paula Julian.363 Revere Beach BLVD.Revere.MA.02151..' from dual
  6      union all
  7      select 'Christine Bast-Friesen.200 E. Carrington Lane.Appleton.WI.54913..' from dual
  8    )
  9  select val,
 10         substr(val,
 11                instr(val,'.',-1,5)+1,
 12                instr(val,'.',-1,4)-instr(val,'.',-1,5)-1
 13               ) city
 14  from data
 15  /
VAL                                                                    CITY
---------------------------------------------------------------------- ---------------
Mary America.1234 Southridge Park Dr..Samna Lorie.MO.31234..           Samna Lorie
Paula Julian.363 Revere Beach BLVD.Revere.MA.02151..                   Revere
Christine Bast-Friesen.200 E. Carrington Lane.Appleton.WI.54913..      Appleton

Re: how to remove dots in the column [message #615976 is a reply to message #615973] Wed, 11 June 2014 07:41 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi Lalit,Thanks for helping

Christine Bast-Friesen(ship_to_name).200 E. CarringtonLane(ship_to_addres).
Appleton(city).WI(sate).54913(zip)..

Instead of Appleton(city) I am getting  200 E. CarringtonLane(ship_to_addres)


Thanks Lalt.
Re: how to remove dots in the column [message #615977 is a reply to message #615976] Wed, 11 June 2014 07:45 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Look at http://www.orafaq.com/forum/mv/msg/193117/615973/#msg_615973 I have updated the query.
Re: how to remove dots in the column [message #615978 is a reply to message #615976] Wed, 11 June 2014 07:45 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator


Of course as Lalit said: "I hope this is what you want as ship_to_address" so he did not give you a query to get "city"!

Quote:
Hi Lalit,Thanks for helping
...
Thanks Lalt.


OK we now know you don't want others to help you, I think I will remove my "solution" then.

Re: how to remove dots in the column [message #615981 is a reply to message #615977] Wed, 11 June 2014 07:49 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Lalit Kumar B wrote on Wed, 11 June 2014 14:45
Look at http://www.orafaq.com/forum/mv/msg/193117/615973/#msg_615973 I have updated the query.


And it does not work for all posted cases:
SQL> col ship_to_name format a25
SQL> col ship_to_addres format a30
SQL> col city format a15
SQL> col state format a6
SQL> col zip format a5
SQL> with
  2    data as (
  3      select 'Mary America.1234 Southridge Park Dr..Samna Lorie.MO.31234..' str from dual
  4      union all
  5      select 'Paula Julian.363 Revere Beach BLVD.Revere.MA.02151..' from dual
  6      union all
  7      select 'Christine Bast-Friesen.200 E. Carrington Lane.Appleton.WI.54913..' from dual
  8    )
  9  SELECT Substr(str, 1, Instr(str, '.', 1, 1) - 1)
 10         ship_to_name,
 11         Substr(str, Instr(str, '.', 1, 1) + 1, Instr(str, '.', 1, 3) -
 12                                                Instr(str, '.', 1, 1) - 1)
 13          ship_to_addres,
 14         Substr(str, Instr(str, '.', 1, 3) + 1, Instr(str, '.', 1, 4) -
 15                                                Instr(str, '.', 1, 3) - 1) city,
 16          Substr(str, Instr(str, '.', 1, 4) + 1, Instr(str, '.', 1, 5) -
 17                                                Instr(str, '.', 1, 4) - 1) state,
 18         Substr(str, Instr(str, '.', 1, 5) + 1, Instr(str, '.', 1, 6) -
 19                                                Instr(str, '.', 1, 5) - 1) zip
 20  from data
 21  /
SHIP_TO_NAME              SHIP_TO_ADDRES                 CITY            STATE  ZIP
------------------------- ------------------------------ --------------- ------ -----
Mary America              1234 Southridge Park Dr.       Samna Lorie     MO     31234
Paula Julian              363 Revere Beach BLVD.Revere   MA              02151
Christine Bast-Friesen    200 E. Carrington Lane         Appleton        WI     54913

[Updated on: Wed, 11 June 2014 07:49]

Report message to a moderator

Re: how to remove dots in the column [message #615982 is a reply to message #615981] Wed, 11 June 2014 07:53 Go to previous messageGo to next message
Michel Cadot
Messages: 68637
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

And even less if someone has a middle initial:
SQL> with
  2    data as (
  3      select 'Mary America.1234 Southridge Park Dr..Samna Lorie.MO.31234..' str from dual
  4      union all
  5      select 'Paula Julian.363 Revere Beach BLVD.Revere.MA.02151..' from dual
  6      union all
  7      select 'Christine Bast-Friesen.200 E. Carrington Lane.Appleton.WI.54913..' from dual
  8      union all
  9      select 'Michel J. Cadot.13 rue de la paix.Paris.FR.75117..' from dual
 10    )
 11  SELECT Substr(str, 1, Instr(str, '.', 1, 1) - 1)
 12         ship_to_name,
 13         Substr(str, Instr(str, '.', 1, 1) + 1, Instr(str, '.', 1, 3) -
 14                                                Instr(str, '.', 1, 1) - 1)
 15          ship_to_addres,
 16         Substr(str, Instr(str, '.', 1, 3) + 1, Instr(str, '.', 1, 4) -
 17                                                Instr(str, '.', 1, 3) - 1) city,
 18          Substr(str, Instr(str, '.', 1, 4) + 1, Instr(str, '.', 1, 5) -
 19                                                Instr(str, '.', 1, 4) - 1) state,
 20         Substr(str, Instr(str, '.', 1, 5) + 1, Instr(str, '.', 1, 6) -
 21                                                Instr(str, '.', 1, 5) - 1) zip
 22  from data
 23  /
SHIP_TO_NAME              SHIP_TO_ADDRES                 CITY            STATE  ZIP
------------------------- ------------------------------ --------------- ------ -----
Mary America              1234 Southridge Park Dr.       Samna Lorie     MO     31234
Paula Julian              363 Revere Beach BLVD.Revere   MA              02151
Christine Bast-Friesen    200 E. Carrington Lane         Appleton        WI     54913
Michel J                   Cadot.13 rue de la paix       Paris           FR     75117

Re: how to remove dots in the column [message #615984 is a reply to message #615981] Wed, 11 June 2014 07:54 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Michel Cadot wrote on Wed, 11 June 2014 18:19
Lalit Kumar B wrote on Wed, 11 June 2014 14:45
Look at http://www.orafaq.com/forum/mv/msg/193117/615973/#msg_615973 I have updated the query.


And it does not work for all posted cases:


Hmm, you are correct. The problem is OP keeps changing his input data. And that's why I said

Lalit Kumar B wrote on Wed, 11 June 2014 16:45
The original question was to remove the extra dots, then in the course the question got changed to get a part of string.


OP has not even followed the Forums Etiquette / Reward Points here and in other forums too Sad
Re: how to remove dots in the column [message #615989 is a reply to message #615982] Wed, 11 June 2014 08:18 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Thanks Lalit & your query also giving me the same as Michel Query

select 'Paula Julian.363 Revere Beach BLVD.Revere.MA.02151..' from dual

SHIP_TO_NAME              SHIP_TO_ADDRES                 CITY            STATE  ZIP
------------------------- ------------------------------ --------------- ------ -----
Mary America              1234 Southridge Park Dr.       Samna Lorie     MO     31234
Paula Julian              363 Revere Beach BLVD.Revere   MA              02151  

SHIP_TO_NAME-->Paula Julian
SHIP_TO_ADDRES-->363 Revere Beach BLVD
CITY-->Revere
STATE -->MA
ZIP-->02151
 Right? Then i am getting the Revere(CITY) in the
363 Revere Beach BLVD.Revere( SHIP_TO_ADDRES )



Please help me
Re: how to remove dots in the column [message #615990 is a reply to message #615989] Wed, 11 June 2014 08:26 Go to previous messageGo to previous message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
When you have scenario like '200 E. Carrington Lane' as ship_to_address, then you need to handle the same in INSTR. Use CASE construct to get the desired output.

The best solution is to fix the root cause, that is to NORMALIZE your data. It's a bad design to have different values in the same column.
Previous Topic: Select Query
Next Topic: Delete statement is taking long time. Please suggest.
Goto Forum:
  


Current Time: Tue Apr 16 16:35:51 CDT 2024