|
〇〇 发表于 2012-11-30 10:35 ![]()
因为全排列的时间在那里,占了总时间的90%
我这里大致占用了80%的时间(48s),connect by在这里没优势
换个写法,效率提高一倍多(17s)
总时间也提高了一倍多点(从65s到29s)
WITH p AS (select rownum n from dual connect by rownum<10),
q AS (select rownum-1 n from dual connect by rownum<=10),
t as (select o1.n a, o2.n*10+o3.n b, o4.n*100+o5.n*10+o6.n c, o7.n*1000+o8.n*100+o9.n*10+o10.n d
from p o1, p o2, p o3, p o4, q o5, p o6, p o7, q o8, q o9, p o10
where not (5 in (o1.n, o3.n, o6.n, o10.n) and 0 in (mod(o1.n,2), mod(o3.n,2), mod(o6.n,2), mod(o10.n,2))) and
o2.n<>o1.n and o3.n not in (o2.n, o1.n) and o4.n not in (o3.n, o2.n, o1.n)
and o5.n not in (o4.n, o3.n, o2.n, o1.n) and o6.n not in (o5.n, o4.n, o3.n, o2.n, o1.n)
and o7.n not in (o6.n, o5.n, o4.n, o3.n, o2.n, o1.n) and o8.n not in (o7.n, o6.n, o5.n, o4.n, o3.n, o2.n, o1.n)
and o9.n not in (o8.n, o7.n, o6.n, o5.n, o4.n, o3.n, o2.n, o1.n)
and o10.n not in (o9.n, o8.n, o7.n, o6.n, o5.n, o4.n, o3.n, o2.n, o1.n)
)
SELECT a||'*'||b||'*'||c||'*'||d||'='||p
FROM (
SELECT * FROM (
SELECT a,b,c,d,TO_CHAR(a*b*c*d) p
FROM t
)
WHERE p=REVERSE(p)
ORDER BY TO_NUMBER(p) DESC
)
WHERE ROWNUM=1; |
|