Skip to content
Advertisement

Oracle : Select only particular value from a row

I have a like below

data :

1234=A||1456=B||1789=C
1245=||1234=V
1234,1133
1456=||1234=1,234||1234

so i wanted to remove all the value after = and before | except for 1234.

expected data :

1234=A||1456=||1789=
1245=||1234=V
1234,1133
1456=||1234=1,234||1234

Advertisement

Answer

You can use:

SELECT REGEXP_REPLACE(
         value,
         '(^||)((1234=.*?)|(d+=).*?)(||$)',
         '1345'
       ) AS value
FROM   table_name

Which, for the sample data:

CREATE TABLE table_name ( value ) AS
SELECT '1234=A||1456=B||1789=C' FROM DUAL UNION ALL
SELECT '1245=||1234=V' FROM DUAL UNION ALL
SELECT '1234,1133' FROM DUAL UNION ALL
SELECT '1456=||1234=1,234||1234' FROM DUAL;

Outputs:

VALUE
1234=A||1456=||1789=
1245=||1234=V
1234,1133
1456=||1234=1,234||1234

sqlfiddle here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement