On 16.05.20 17:18, Alex Magnum wrote:

> Now I try to remove the last  field and comma  ",Class"
> 
> To get  Class V,Class VI,Class VII,Competitive Exam,Class VIII
> 
> Is there a function or easy way to do this?
> Any help would be appreciated.
> 

Hi Alex

Many options to do this with regexp_replace, here's one way:


with test as (
        select 'Class VII,Competitive Exam,Class VIII,Class' as str
        union
        select 'Class VIIx,Competitive Exam22,Class VIIIabc,Classx'
)
select str, regexp_replace(str, '^(.*),(.*?)$', '\1') res from test;


|str
                             |res
                                                          |
|------------------------------------------------------|
|Class VII,Competitive Exam,Class VIII,Class
                             |Class VII,Competitive Exam,Class VIII

|------------------------------------------------------|
|Class VIIx,Competitive Exam22,Class VIIIabc,Classx
                             |Class VIIx,Competitive Exam22,Class
VIIIabc                                                         |


(I cut some columns at the start to better fit email width)

Cheers
Christian


-- 
Christian Ramseyer, netnea ag
Network Management. Security. OpenSource.
https://www.netnea.com







Reply via email to