Oracle PL/SQL 查询从组合变为最大值

问题描述 投票:0回答:0

我有一个 sql 查询,基本上比较 2 个子查询,如下所示。子查询 A 获取员工代码的可能组合值,这些值是从员工表中用连字符分隔的,并比较从部门表中生成的相同代码列表。

我需要更改查询,而不是组合组合列表,从部门和员工表中获取最大组合连字符分隔值,然后比较并返回匹配的组合。 基本上需要更改使用 listagg 的子查询,但我很困惑如何才能做到这一点。 通过最大的最长代码组合。

select emp_code from (
select emp_code,lengthb(emp_code)
from (select (select listagg (emp_comb_value,'-') within group (order by emp_comb_value) from 
(select regexp_substr (emp_code,'[^-]+',1,level) emp_comb_value from dual connect by regexp_substr(,'[^-]+',1,level) is not null)) emp_comb_value,emp_code from employees e)a,
(select substr(sys_connect_by_[ath(labour_code,'-'),2) as combined_value from (select labour_code,dept_id from departments where business_unit= :BUSINESS_UNIT) connect by prior labour_code <labour_code) b where a.emp_cpmb_value=b.combined_Value order by 2 desc_ where rownum=1;
oracle plsql plsqldeveloper
© www.soinside.com 2019 - 2024. All rights reserved.