-- Created on 2019/4/1 by IRIS.ZHOU
declare
--cursor c_cursor is select cid from classes partition(class_sex_l01) for update;
cursor s_cursor is select * from stues for update;
-- Local variables here
-- Local variables here
i number(6);
rn number(3);
--c_type c_cursor%rowtype;
s_type s_cursor%rowtype;
-- cid number(6);
-- cnum number(6);
begin
-- Test statements here
/**
添加數據
for i in 1..200 loop
insert into classes values(S_ID.NEXTVAL,S_ID.NEXTVAL*8,'班級'||i,ceil((i+50)/5),floor((i+50)/5)+5,mod(i,2)+1);
end loop;
**/
/**
--修改數據
for i in (select cid from classes partition(class_sex_l02)) loop
update classes partition(class_sex_l02) set cmax_age=ceil((i.cid+50)/5) where cid=i.cid ;
end loop;
**/
/**
使用游標修改
**/
/**
for c_type in c_cursor loop
update classes partition(class_sex_l01) set cmax_age=ceil((c_type.cid+50)/4)+5 where current of c_cursor;
end loop;
**/
/**
--刪除數據
delete classes partition(class_sex_l02) where cid=199;
**/
/**
添加學生表信息
for i in 1..299 loop
insert into stues values(S_ID.NEXTVAL,S_ID.NEXTVAL*9,'name'||i,(ceil(i/4))+1,mod(i,2)+1,1);
end loop;
**/
/**
修改學生表信息
**/
for s_type in s_cursor loop
select ceil(dbms_random.value(1,180)) into rn from dual;
update stues set scid=rn where current of s_cursor;
end loop;
commit;
end;