WITH t AS ( SELECT 'a' id FROM dual UNION ALL SELECT 'b' FROM dual UNION ALL SELECT 'c' FROM dual UNION ALL SELECT 'd' FROM dual ) SELECT t1.id||t2.id FROM t t1,t t2 WHERE t1.id<t2.id;
自连接做个迪卡尔集,再比较ASCII码大小。with t as ( --NO NAME select 1 as num, 'A' as name from dual union all select 2, 'B' from dual union all select 3, 'C' from dual union all select 4, 'D' from dual ) select aname || bname from ( select a.num as anum,a.name as aname,b.num as bnum, b.name as bname from t a, t b) where ascii(aname) < ascii(bname)ANAME||BNAME ------------ AB AC AD BC BD CD
SELECT 'a' id FROM dual
UNION ALL
SELECT 'b' FROM dual
UNION ALL
SELECT 'c' FROM dual
UNION ALL
SELECT 'd' FROM dual
)
SELECT t1.id||t2.id FROM t t1,t t2 WHERE t1.id<t2.id;
--NO NAME
select 1 as num, 'A' as name from dual
union all
select 2, 'B' from dual
union all
select 3, 'C' from dual
union all
select 4, 'D' from dual
)
select aname || bname from (
select a.num as anum,a.name as aname,b.num as bnum, b.name as bname from t a, t b)
where ascii(aname) < ascii(bname)ANAME||BNAME
------------
AB
AC
AD
BC
BD
CD