Home » SQL & PL/SQL » SQL & PL/SQL » Regular Expressions (Oracle)
Regular Expressions [message #664213] |
Fri, 07 July 2017 02:33 |
|
oomjai2233
Messages: 6 Registered: July 2017
|
Junior Member |
|
|
Hi Team,
I need to replace the same character(remove Duplicate char) from a column.
Source:
empid region
1 C
2 L,L,L,L
3 L,E,E,L,P
4 A,A,S,D
5 A,A
So i want output like below
empid region
1 C
2 L
3 L,E,P
4 A,S,D
5 A
|
|
|
|
|
|
|
|
Re: Regular Expressions [message #664219 is a reply to message #664218] |
Fri, 07 July 2017 03:14 |
John Watson
Messages: 8951 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
And the CREATE TABLE REGION_TEST statement? With the five INSERT statements?
PErhaps someone will help if you do that - not me, I'm going to a client site now.
|
|
|
|
Re: Regular Expressions [message #664221 is a reply to message #664219] |
Fri, 07 July 2017 03:18 |
|
Michel Cadot
Messages: 68693 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
John Watson wrote on Fri, 07 July 2017 10:14...
PErhaps someone will help if you do that - not me, I'm going to a client site now.
I will if oomjai2233 follows the rules, posts what is asked, answers the questions, and shows us what he tried from the topic I pointed him/her to.
[Updated on: Fri, 07 July 2017 03:18] Report message to a moderator
|
|
|
Re: Regular Expressions [message #664224 is a reply to message #664221] |
Fri, 07 July 2017 04:30 |
|
oomjai2233
Messages: 6 Registered: July 2017
|
Junior Member |
|
|
sure my code is here
create table qa_poc_hp.REGION(EMPID INTEGER,REGION VARCHAR(20))
INSERT INTO QA_POC_HP.REGION VALUES(1,'C');
INSERT INTO QA_POC_HP.REGION VALUES(2,'L,L,L,L');
INSERT INTO QA_POC_HP.REGION VALUES(3,'L,E,E,L,P');
INSERT INTO QA_POC_HP.REGION VALUES(4,'A,A,S,D');
INSERT INTO QA_POC_HP.REGION VALUES(5,'A,A');
sample records
EMPID REGION
1 C
2 L,L,L,L
3 L,E,E,L,P
4 A,A,S,D
5 A,A
the query i m running
SELECT EMPID,REGEXP_REPLACE(REGION|| ',',' ([^,]+)(,[ ]*\1)+ ,'\1') FROM REGION ;
The version is ,Oracle 11g
|
|
|
|
Re: Regular Expressions [message #664226 is a reply to message #664225] |
Fri, 07 July 2017 05:18 |
|
oomjai2233
Messages: 6 Registered: July 2017
|
Junior Member |
|
|
Hi,i have seen the code but when i am applying that in to my code it is behaving something different.i am more interested in single line function(regexp_replace).
Mysql
SELECT empid,REGEXP_REPLACE(region,'(^|\-)([^-]+\-)(.*\-)?\2','\1\2\3') FROM REGION
my output not changed
empid REGEXP_REPLACE
5 A,A
4 A,A,S,D
3 L,E,E,L,P
1 C
2 L,L,L,L
|
|
|
|
|
|
Goto Forum:
Current Time: Sat Sep 28 06:48:24 CDT 2024
|