Oracle cursor example

-- Created on 2013/9/10 by DAMON 
declare 
  -- Local variables here
  cursor sec_cur is
  select dsi.section_id from dict_section_info dsi where dsi.section_name like '%手术室%';
  t_section_id dict_section_info.section_id%Type;
begin
  -- Test statements here
   open sec_cur;  
   Loop   
     Fetch sec_cur into t_section_id;  
     Exit when sec_cur%notfound;  
           insert into clinic_section_compare(COMPARE_ID,SECTION_ID,CLINIC_SECTION_ID)
                  values(clinic_section_compare_seq.nextval,t_section_id,22);
   end loop;  
   Exception   
     when others then  
         close sec_cur;  
         Dbms_Output.put_line(Sqlerrm);  
           
   if sec_cur%isopen then     
      close sec_cur;  
   end if;  
end;


你可能感兴趣的:(Oracle cursor example)