解决方案 »

  1.   

    --提供个思路
    select sum(col_name) from tab_name order by dbms_random.random;
      

  2.   

    假设表为T,字段为N,规定的数字综合为20,数字个数为4
    SELECT LTRIM(A.NS,'+') NS FROM
      (select NS,RS from (select sys_connect_by_path(N,'+') NS,sys_connect_by_path(rowid,',') RS,level v_level
                          from T connect by prior rowid<rowid and level<=4)
      where v_level=4) A,T B 
    WHERE INSTR(A.RS,B.ROWID)>0
    GROUP BY A.RS,A.NS
    HAVING SUM(B.N)=20
    ORDER BY A.NS
    可以根据需要调整相关参数
    测试通过,测试数据20条 分别为1~20
    测试结果
    NS
    1+2+3+14
    1+2+4+13
    1+2+5+12
    1+2+6+11
    1+2+7+10
    1+2+8+9
    1+3+4+12
    1+3+5+11
    1+3+6+10
    1+3+7+9
    1+4+5+10
    1+4+6+9
    1+4+7+8
    1+5+6+8
    2+3+4+11
    2+3+5+10
    2+3+6+9
    2+3+7+8
    2+4+5+9
    2+4+6+8
    2+5+6+7
    3+4+5+8
    3+4+6+7
      

  3.   

    这个考验算法,最好用存储过程来做,SQL语句的话效率可能将极为糟糕