I have come across below query, but I am not able to conclude my analysis related to below query. The main aim of the below query is to convert the number to the alphabet. But the usage of the hierarchical query made me confuse.
merge into s_export ex
using (
select
listagg(n, '') within group (order by lv) new_val,
row_id
from
(
SELECT
connect_by_root rowid row_id,
LEVEL lv,
CASE
WHEN Regexp_like(Regexp_substr( file_as, '[^0-9]+|((\d+)(st|nd|rd|th)?)', 1, LEVEL ), '\d+')
THEN spell_number(
Regexp_substr( file_as, '[^0-9]+|((\d+)(st|nd|rd|th)?)', 1, LEVEL, NULL, 2),
Regexp_substr( file_as, '[^0-9]+|((\d+)(st|nd|rd|th)?)', 1, LEVEL, NULL, 3)
)
ELSE Regexp_substr( file_as, '[^0-9]+|((\d+)(st|nd|rd|th)?)', 1, LEVEL )
END N
FROM s_export d
CONNECT BY NOCYCLE Regexp_substr( file_as, '([^0-9]+)|(\d+)(st|nd|rd|th)?', 1, LEVEL ) IS NOT NULL
and rowid = prior rowid
and prior dbms_random.value is not null
)
group by row_id
) t
on (t.row_id = ex.rowid)
when matched then
update set ex.file_as = t.new_val;
Sample Dataset:
create table s_export (file_as varchar2(2000));
insert into s_export values ('Collection Four') ;
insert into s_export values ('OM_Forty-One One');
insert into s_export values ('OM_Twenty-Two | SOFifteen');
insert into s_export values ('1st');
insert into s_export values ('3M');
insert into s_export values ('Collection Six');
insert into s_export values ('2ND');
insert into s_export values ('11TH100');
Below is my understanding so far:
We are performing an update on the table
s_export
columnfile_as
whenever there is any number say1
, it will convert this to'one'
.As far as
LEVEL
used inRegexp_substr
work as an occurrence.