用遊標打開考场表--example僅供參考create or replace procedure pro_test
as
     cursor cur_test is
     select 编号 from 考场表;
     is_id  number(10);
     is_limit number(10);
     is_min_id number(20);
begin
     select min(学生id) into is_min_id from 学生表;
     
     open cur_test;
     loop
          fetch cur_test into is_id;
          exit when cur_test%notfound;
 
          select 容量 into is_limit
          from   考场表
          where  编号 = is_id ;          insert into 准考证表(
                 学生id       ,
                 考场编号     )
          select 学生id       ,
                 is_id        
          from  (select * from 学生表
                 where 学生id >= is_min_id
                 order by 学生id)
          where rownum <= is_limit ;          select 学生id into is_min_id
          from  (select * from 学生表
                 where 学生id >= is_min_id+1
                 order by 学生id
                 minus
                 select * from 学生表
                 where 学生id >= is_min_id
                 order by 学生id
                )
          where  rownum =1 ;     end loop;
     close cur_test;     commit;
end;
/