|
〇〇 发表于 2015-8-13 11:17 ![]()
经过一番改写,我的也毫秒出了,缺点是人工认为9位最长
with t as(select level-1 l from dual connect by ...
改好了
with t as(select level-1 l from dual connect by level<=10)
,t3 as(select distinct a.l||b.l||c.l l from t a,t b,t c where a.l*a.l/2>b.l*c.l
and a.l<>b.l and b.l<>c.l and c.l<>a.l)
,t4 as(select distinct a.l||substr(b.l,-1) l from t3 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t5 as(select distinct a.l||substr(b.l,-1) l from t4 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t6 as(select distinct a.l||substr(b.l,-1) l from t5 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t7 as(select distinct a.l||substr(b.l,-1) l from t6 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t8 as(select distinct a.l||substr(b.l,-1) l from t7 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t9 as(select distinct a.l||substr(b.l,-1) l from t8 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,t10 as(select distinct a.l||substr(b.l,-1) l from t9 a,t3 b
where substr(a.l,-2,2)=substr(b.l,1,2) and instr(a.l,substr(b.l,-1))=0)
,taihaole as(select nvl((select max(to_number(l)) from t3),0)c3,
nvl((select max(to_number(l)) from t4),0)c4,
nvl((select max(to_number(l)) from t5),0)c5,
nvl((select max(to_number(l)) from t6),0)c6,
nvl((select max(to_number(l)) from t7),0)c7,
nvl((select max(to_number(l)) from t8),0)c8,
nvl((select max(to_number(l)) from t9),0)c9,
nvl((select max(to_number(l)) from t10),0)c10
from dual)
select greatest(c3,c4,c5,c6,c7,c8,c9,c10) from taihaole; |
|