Oracle does this as below, can any one help me in converting the below to sql1 with t as (select 1 as rn, 'ABC|AVC1|1234|' as txt from dual union all 2 select 2, 'xyz|abc' from dual union all 3 select 3, 'ABC1|AVC1|12334|' from dual union all 4 select 4, 'xyz' from dual union all 5 select 5, '|ABC' from dual union all 6 select 6, 'ABC1|AVC1|12334|xyz|ABC' from dual) 7 -- END OF TEST DATA 8 select rn, txt 9 from ( 10 select rn, regexp_substr(txt, '^[^|]+\|[^|]+\|[^|]+\|[^|]+\|[^|]+') as txt 11 ,case when s < nvl(lag(s) over (order by rn),999) then 1 else 0 end as s 12 from ( 13 select rn, replace(txt||'|'||lead(txt) over (order by rn) 14 ||'|'||lead(txt,2) over (order by rn) 15 ||'|'||lead(txt,3) over (order by rn) 16 ||'|'||lead(txt,4) over (order by rn),'||','|') as txt 17 ,mod(sum(length(regexp_replace(txt,'[^|]'))) over (order by rn),5) as s 18 from t 19 ) 20 ) 21 where s = 1 22* order by rnSQL> / RN TXT---------- ------------------------------ 1 ABC|AVC1|1234|xyz|abc 3 ABC1|AVC1|12334|xyz|ABC 6 ABC1|AVC1|12334|xyz|ABC SQL>
ignoring the WITH clause the query (which is just test data and saves me creating a table on my database) and replace "t" in the main query with the name of table