oracle中的游标的原理和使用详解(三)

2015-01-21 11:11:12 · 作者: · 浏览: 107
); kc varchar2 (50 ); type ref_cursor is ref cursor; --声明一个ref游标类型 stu_cursor ref_cursor ;--定义一个ref游标类型的变量 type tab_type is table of number; --声明一个table类型 tab_xh tab_type ;--定义一个表类型的变量 cursor cursor_xh is select distinct( xh) from student; --声明一个游标 begin open cursor_xh; --打开游标 fetch cursor_xh bulk collect into tab_xh; --提取数据到表中 for i in 1 .. tab_xh.count loop kcs :='' ; open stu_cursor for select kc from student s where s.xh = tab_xh(i ); --打开ref游标 fetch stu_cursor into kc ; --移动游标 while stu_cursor %found loop kcs := kc ||kcs ; --连接字符串使用||而不是+ fetch stu_cursor into kc ; --移动游标 end loop; insert into student2 (xh , kc ) values( i, kcs); close stu_cursor ; end loop; close cursor_xh ; end;

?