17,086
社区成员
发帖
与我相关
我的任务
分享
--1.使用游标和loop循环来显示所有部门的名称
--游标声明
declare
--select语句
cursor csr_dept is select dname from depth;
--指定行指针,这句话应该是指定和csr_dept行类型相同的变量
row_dept csr_dept%rowtype;
begin
--for循环
for row_dept in csr_dept loop
dbms_output.put_line('部门名称:'||row_dept.dname);
end loop;
end;
/
--2.使用游标和while循环来显示所有部门的的地理位置(用%found属性)
declare
--游标声明
cursor csr_testwhile is select loc from depth;
--指定行指针
row_loc csr_testwhile%rowtype;
begin
--打开游标
open csr_testwhile;
--给第一行填充数据
fetch csr_testwhile into row_loc;
--测试是否有数据,并执行循环
while csr_testwhile%found loop
dbms_output.put_line('部门地点:'||row_loc.loc);
--给下一行填充数据
fetch csr_testwhile into row_loc;
end loop;
close csr_testwhile;
end;
/