问题可以描述成 某个(did 表示班级id)班男女生站队问题 tableA 存放所有学生,tableB存放能站一对的人,第一次写这种 求指教啊    --创建存储过程!  
    create or replace procedure pro_test_for(did int)   
    as  
    len int;  --定义变量;  
i int;
    begin 
    i:= 0; 
    len:= select count(*) from tableA where ctype = 0 and id = did;        
    if(len < (select count(*) from tableA where ctype = 0 and id = did )) 
     len := select count(*) from tableA where ctype = 0 and id = did;
    --循环10000次.  
    for i in 1..len loop  
      --插入数据到表中.  
      insert into tableB values((select sname from tableA where ctype = 0 and id = did),(select sname from tableA where ctype = 0 and id = did));  
    end loop; 
    commit;  
    end pro_test_for;

解决方案 »

  1.   

    忘了序号了    --创建存储过程!  
        create or replace procedure pro_test_for(did int)   
        as  
        len int;  --定义变量;  
    i int;
        begin 
        i:= 0; 
        len:= select count(*) from tableA where ctype = 0 and id = did;        
        if(len < (select count(*) from tableA where ctype = 0 and id = did )) 
         len := select count(*) from tableA where ctype = 0 and id = did;
        --循环10000次.  
        for i in 1..len loop  
          --插入数据到表中.  
          insert into tableB values((select sname from tableA where ctype = 0 and id = did and pid = i),(select sname from tableA where ctype = 0 and id = did and pid = i));  
        end loop; 
        commit;  
        end pro_test_for;
      

  2.   

    存储过程传的参数是班级ID,
    代码中,直接:insert into tableb(columna,columnb....) select avalue,bvalue.... from tablea where 班级ID= 传的班级ID。commit;