码迷,mamicode.com
首页 > 数据库 > 详细

pl/sql实现排列组合中组合

时间:2016-02-01 19:11:58      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:pl/sql

 procedure zuhev(n      number,
                   arrvar out t_arrchar) is
    idx number;
    m   number;
    x   number := 1;
    type arrayty is table of number index by binary_integer;
    -- nlarr nlarrarty;
    -- arr arrayty;
    p    arrayty;
    a    arrayty;
    tmps varchar2(1000);
  begin
    for i in 1 .. n
    loop
      a(i) := i;
    end loop;
    for i in 1 .. n
    loop
      p(i) := i;
    end loop;
    for i in 0 .. n
    loop
      m := i;
      begin
        idx := 1;
        p(idx) := 1; --//取第一个元素
        while (true)
        loop
          if (p(idx) > n) then
            --//取到底了,回退
            if (idx = 1) then
              --//各种情况取完了,不能再回退了
              exit;
            end if;
            --}
            idx := idx - 1; --;//回退到前一个
            p(idx) := p(idx) + 1; --//替换元素       
            --   }
          elsif (idx = m) then
            --//取够了,输出
            for i in 1 .. m
            loop
              tmps := tmps || to_char(a(p(i)));
            end loop;
            arrvar(x) := tmps;
            tmps := null;
            p(idx) := p(idx) + 1; --//替换元素   
            x := x + 1;
          else
            --{//多取一个元素
            idx := idx + 1;
            p(idx) := p(idx - 1) + 1;
            --}
          end if;
        end loop;
      end;
    end loop;
    /*  for i in 1 .. arrvar.count
    loop
    dbms_output.put_line(to_char(arrvar(i)));
    end loop;*/
  end;

本文出自 “ORACLE/DB2/MYSQL” 博客,谢绝转载!

pl/sql实现排列组合中组合

标签:pl/sql

原文地址:http://383610.blog.51cto.com/373610/1740343

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!