vatsal vatsal - 4 months ago 25
SQL Question

Remove duplicate number from each row in sql

I have this table:

A B C
Abc. Bcd. 1223
Abc. Bdh. 144777


I want to remove duplicates from each row in
C
column. Output should be like:

A B C
Abc. Bcd. 123
Abc. Bdh. 147


I am using SAP hana so many functions of sql does not work there.

Answer

Why not use regular expressions like here (Regex to remove duplicate letters)?

select REPLACE_REGEXPR ('([A-Za-z0-9])\1+' in 'AA2234b23' 
                        WITH '\1' 
                        OCCURRENCE ALL) 
from dummy;

result: A234b23