问题可以描述成 某个(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;
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;
解决方案 »
- 写查询语句遇到个排序的怪现象
- JDBC连接Oracle10g数据库重启电脑之后就连接不上了错误信息如下
- oracle exp/imp问题。新手学习oracle
- 在ORACLE中,怎么在字段中保存图片~~~~~急~~~送分50
- oracle.sdoapi.OraSpatialManager 找不到
- ORA-01489: result of string concatenation is too long
- 请问大家装哪个版本的oracle,个人电脑怎么装?
- ORACLE 9i的意义?
- 在delphi中用adoquery执行一个带有输入参数和输出参数的oracle存储过程,该怎么做?
- 在触发器里能调用函数或则存储过程吗?
- 关于数据库集群的困惑,希望大神解答
- Oracle数据库文件位置调整
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;
代码中,直接:insert into tableb(columna,columnb....) select avalue,bvalue.... from tablea where 班级ID= 传的班级ID。commit;