游标在Oracle数据库中使用:
主要适用于查询数据返回多行,使用游标存储返回的多行数据,类似于集合,遍历循环做操作。
1,代码
declare
cursor ft is
select t.username, t.create_time
from com11_employee t
where t.department_id = 16
and rownum <= 10; --创建游标
nameA com11_employee.username % type; --声明变量,用户存储游标中取出的值
timeB com11_employee.create_time % type;
begin
open ft; --打开游标
loop
fetch ft
into nameA, timeB; --从游标中取值赋值给变量
exit when ft % notfound; --特殊情况判断
dbms_output.put_line(nameA || timeB);
end loop;
close ft; --关闭游标
end;
2,执行结果