--显式游标遍历数据
declare
cursor data_rows is select * from all_tables where num_rows>0 order by num_rows desc;
data_row data_rows%rowtype; --定义data_row是data_rows的一行数据
begin
open data_rows;--游标使用前需打开
fetch data_rows into data_row; --从游标中取一行数据
while data_rows%found --找到数据
loop --开始循环
dbms_output.put_line('表名:'||data_row.table_name||' 数据行:'||data_row.num_rows);
fetch data_rows into data_row; --再取一行
end loop;
close data_rows;--游标使用结束需关闭
end;
--隐式游标等价写法
begin
for item in(select * from all_tables where num_rows>0 order by num_rows desc)
loop
dbms_output.put_line('表名:'||item.table_name||' 数据行:'||item.num_rows);
end loop;
end;