一切变异都来自收获(Oracle)

kwvwclae  于 2022-11-22  发布在  Oracle
关注(0)|答案(1)|浏览(119)

我想生成所有可能的变化,而不重复。我已经准备了一个数据集和查询,以及预期的结果

with t as (
  select 'A' as col1 from dual
  union all
  select 'B' as col1 from dual
  union all
  select 'C' as col1 from dual
)
select * from t

with t as (
      select 'A' as col1, 'B' as col2, 'C' as col3 from dual
    )
    select * from t

我想得到什么?:

A;
A;B
A;B;C
A;C
B;
B;C
C;

行的顺序不相关,元素没有顺序,因此它们不能:A;B和B;A
它可以工作,但返回重复的变体:

select sys_connect_by_path( col1, ';' )
from t
connect by nocycle col1 <> prior col1
1tuwyuhd

1tuwyuhd1#

可以使用下面的代码:

with t as (
  select 'A' as col1 from dual
  union all
  select 'B' as col1 from dual
  union all
  select 'C' as col1 from dual
) 
select substr(sys_connect_by_path( col1, ';' ),2)
from t
connect by nocycle col1 < prior col1;

相关问题