複数のフィールドを連結する必要がありますが、null である場合とそうでない場合があります。',,c,,e,,' のような文字列になる可能性がありますが、これは実際には 'c,e' として表示したいものです。
regexp_replace
との組み合わせでこれを取得できますtrim
:
with sd as (select 'a,b,c' str from dual union all
select 'a' str from dual union all
select null str from dual union all
select 'a,,,d' from dual union all
select 'a,,,,e,f,,'from dual union all
select ',,,d,,f,g,,'from dual)
select str,
regexp_replace(str, '(,)+', '\1') new_str,
trim(both ',' from regexp_replace(str, '(,)+', '\1')) trimmed_new_str
from sd;
STR NEW_STR TRIMMED_NEW_STR
----------- ----------- ---------------
a,b,c a,b,c a,b,c
a a a
a,,,d a,d a,d
a,,,,e,f,, a,e,f, a,e,f
,,,d,,f,g,, ,d,f,g, d,f,g
regexp_replace
しかし、私はそれが1回だけで実行可能であるべきだと感じています.
出来ますか?もしそうなら、どのように?