【发布时间】:2018-10-12 22:39:28
【问题描述】:
我遇到了以下查询,但我无法得出与以下查询相关的分析。以下查询的主要目的是将数字转换为字母表。但是分层查询的用法让我很困惑。
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;
样本数据集:
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');
以下是我目前的理解:
我们正在对表
s_export列执行更新file_as只要有任何数字说1,它就会转换这个 到'one'。就
LEVEL中使用的Regexp_substr而言,作为一个事件发生。
【问题讨论】:
-
从表
s_export中获取一些样本数据,然后您可以使用sqlfiddle.com dbfiddle.uk rextester.com/l/oracle_online_compiler 之类的服务来设置选择查询(不是更新)并研究结果。如果您仍然遇到问题,请将 URL 粘贴到示例中,以便我们提供帮助。没有样本数据 = 我们无能为力 -
@Used_By_Already 示例数据已更新,
-
是的,我看到了示例数据,但我没有函数 spell_number()。我建议您只从
select ... to ... group by row_id运行该查询的一部分并检查该结果 -
是的,我已经执行了,但是很遗憾,该功能不起作用。
标签: sql oracle11g hierarchical listagg regexp-substr