comparing two fields [message #313913] |
Tue, 15 April 2008 03:01  |
alister
Messages: 101 Registered: August 2007 Location: India
|
Senior Member |
|
|
Dear Friends
I am having a table with the following two columns and some sample data. In Bankaddress1 the bankname is repeated. Can anyone tell me of a way in which I can remove the Bankname from bankaddress1.
BANKNAME BANKADDRESS1
STATE BANK OF INDIA STATE BANK OF INDIA, GUDIYA
SYNDICATE BANK SYNDICATE BANK SOUTHRAM PART
INDIAN BANK INDIAN BANK NILAMBUR
ING VYSYA BANK 41, RAHMAN COMPLEX,
CORPORATION BANK CORPORATION BANK 100 FEET ROAD
STATE BANK OF INDIA STATE BANK OF INDIA
INDIAN OVERSEAS BANK INDIAN OVERSEAS BANK KANDIYUR
STATE BANK OF INDIA STATE BANK OF INDIA,SOUTH
INDIAN OVERSEAS BANK IOB, CRAWFORD,TRICHY-12
CORPORATION BANK CORPORATION BANK,V.KOOTU RD,
Thanking you
Alister
|
|
|
|
Re: comparing two fields [message #313915 is a reply to message #313913] |
Tue, 15 April 2008 03:05   |
alister
Messages: 101 Registered: August 2007 Location: India
|
Senior Member |
|
|
Hi
I am sorry it did not upload properly. The Bankname and Bankaddress1 have been concatinated. ie 'STATE BANK OF INDIA STATE BANK OF INDIA'. One of them have to be removed.
Thanks
Alister
|
|
|
|
Re: comparing two fields [message #314195 is a reply to message #313913] |
Wed, 16 April 2008 00:58   |
alister
Messages: 101 Registered: August 2007 Location: India
|
Senior Member |
|
|
Dear Friends
I tried a little bit of formatting so please execuse the clumsyness.
BANKNAME , BANKADDRESS1
BBcode
STATE BANK OF INDIA , STATE BANK OF INDIA, GUDIYA BBcode
SYNDICATE BANK , SYNDICATE BANK SOUTHRAM PART BBcode
INDIAN BANK , INDIAN BANK NILAMBUR BBcode
CORPORATION BANK , CORPORATION BANK 100 FEET ROAD BBcode
STATE BANK OF INDIA , STATE BANK OF INDIA BBcode
INDIAN OVERSEAS BANK , INDIAN OVERSEAS BANK KANDIYUR BBcode
STATE BANK OF INDIA , STATE BANK OF INDIA,SOUTH BBcode
CORPORATION BANK , CORPORATION BANK,V.KOOTU RD,
The red letters should be removed from the second part. The red is one column (Bankname)and the black is the second column(
Bankaddress1).
Thank you
Alister
[Updated on: Wed, 16 April 2008 01:00] Report message to a moderator
|
|
|
Re: comparing two fields [message #314202 is a reply to message #313913] |
Wed, 16 April 2008 01:23   |
 |
MarcS
Messages: 312 Registered: March 2007 Location: Antwerp
|
Senior Member |
|
|
Have a look how others format their post ( use the "quote" button to have a peek )
If I'm not misunderstanding you, this is what you are looking for:
SQL*Plus: Release 10.1.0.5.0 - Production on Wo Apr 16 08:22:25 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>
SQL> prompt Just a select to mimic the data
Just a select to mimic the data
SQL>
SQL> select 'STATE BANK OF INDIA' col1 , 'STATE BANK OF INDIA, GUDIYA BBcode' col2
2 from dual
3 ;
COL1 COL2
------------------- ----------------------------------
STATE BANK OF INDIA STATE BANK OF INDIA, GUDIYA BBcode
SQL>
SQL> prompt Remove stuff of col1 from col2, notice there is still "rubbish" at the begining
Remove stuff of col1 from col2, notice there is still "rubbish" at the begining
SQL>
SQL> select replace(col2,col1,'')
2 from (
3 select 'STATE BANK OF INDIA' col1 , 'STATE BANK OF INDIA, GUDIYA BBcode' col2
4 from dual
5 )
6 ;
REPLACE(COL2,CO
---------------
, GUDIYA BBcode
SQL>
SQL> prompt Get rid of the "rubbish" as well
Get rid of the "rubbish" as well
SQL>
SQL> select ltrim(replace(col2,col1,''),', ')
2 from (
3 select 'STATE BANK OF INDIA' col1 , 'STATE BANK OF INDIA, GUDIYA BBcode' col2
4 from dual
5 )
6 ;
LTRIM(REPLACE
-------------
GUDIYA BBcode
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
|
|
|
|
|
Re: comparing two fields [message #314495 is a reply to message #313913] |
Wed, 16 April 2008 22:46  |
alister
Messages: 101 Registered: August 2007 Location: India
|
Senior Member |
|
|
Quote: | Dear MarcS
Thank you so much. The code you have given me gave me the desired output. I think I got the formating right this time.
Thank you.
Alister
|
|
|
|