使用【游标】可以辅助实现一行一行地遍历某个数据库表中的所有行。 例如在Oracle数据库中: declare sname varchar2( 20); --声明变量 cursor student_cursor is select sname from student ; --声明指向表student的【游标】 begin open student_cursor;--打开游标 fetch student_cursor into sname ;--获取游标的当前指向值,使游标指针往下移动 while student_cursor%found --判断游标指针是否指向某行记录,即是否已遍历完全表 loop--循环遍历 dbms_output.put_line ('学生姓名' ||sname );--输出当前遍历访问的行记录信息 fetch student_cursor into sname;--获取游标的当前指向值,使游标指针往下移动 end loop;--循环体结束 close student_cursor;--关闭游标,对应前面open操作 end;