存储过程和循环迭代

create or replace procedure exam_temp_produce
as
CURSOR lib_ids IS select ss.dir_id,ss.dir_site_id from directorys ss where ss.dir_name = '演示目录';

BEGIN
    --试题库、试卷、考试
    FOR A IN lib_ids LOOP
    insert into directorys(dir_id,dir_site_id,dir_parent_id,dir_name,dir_desc,dir_is_avail,dir_start_time,dir_end_time,dir_create_time,dir_create_user,dir_update_time,dir_update_user,dir_sort)
    values(directorys_seq.nextval,A.dir_site_id,A.dir_id,'试题库','试题库','Y',sysdate,sysdate,sysdate,2,sysdate,2,1);
    insert into directorys(dir_id,dir_site_id,dir_parent_id,dir_name,dir_desc,dir_is_avail,dir_start_time,dir_end_time,dir_create_time,dir_create_user,dir_update_time,dir_update_user,dir_sort)
    values(directorys_seq.nextval,A.dir_site_id,A.dir_id,'试卷','试卷','Y',sysdate,sysdate,sysdate,2,sysdate,2,2);
    insert into directorys(dir_id,dir_site_id,dir_parent_id,dir_name,dir_desc,dir_is_avail,dir_start_time,dir_end_time,dir_create_time,dir_create_user,dir_update_time,dir_update_user,dir_sort)
    values(directorys_seq.nextval,A.dir_site_id,A.dir_id,'考试','考试','Y',sysdate,sysdate,sysdate,2,sysdate,2,3); 
    END LOOP;
  COMMIT;

  EXCEPTION WHEN OTHERS THEN
    ROLLBACK;

END exam_temp_produce;

你可能感兴趣的:(存储过程)