--显示游标的使用 --1、声明游标 cursor cursor_name--游标名称 [(parameter_name datatype...)]--带参数游标的参数,(参数名 参数类型)-(v_t number(10,2)) is select_statement--select语句 --2、打开游标 open cursor_name --3、读取数据 fetch cursor_name into record_name--将游标查询的值赋值给record_name参数或参数列表 --4、关闭游标 close cursor_name --Bulk Collect into [参数列表] limit [每次批量提取的数据] --Bulk Collect into方式批量提取游标 --实例 declare cursor cur_t is select id,name from table_name; type prc_table is table of table_name%rowtype; prc_t prc_table; begin open cur_t;--打开游标 loop fetch cur_t bulk collect into prc_t limit 2;--每次批量提取2条数据 for i in 1..prc_t.count loop dbms_output.put_line(prc_t(i).id||prc_t(i).name); end loop; exit when cur_t%NOTFOUND;--当游标中没有数据是退出Loop end loop; close cur_t;--关闭游标 end; --cursor for loop 组合使用 declare cursor cur is select '1' as id, 'xx' as name from dual; begin for cur_t in cur--将声明好的游标cur赋值给cur_t;被赋值的变量,类型为%ROWTYPE; loop dbms_output.put_line(cur_t.id||' '||cur_t.name); end loop; end; --显示游标的属性 %ISOPEN :判断游标是否打开。返回 boolean 类型。 %FOUND :检测是否提取到有效的数据。返回 boolean 类型。 %NOTFOUND :与%FOUND 效果相反。 %ROWCOUNT :累计到目前位置游标提取到的数据行数。 --游标属性的使用方法 cursor_name%ISOPEN --直接在声明好游标后添加使用,主要用于判断 --隐式游标 隐式游标是有PL/SQL自动管理,不需要声明。 隐式游标默认名称为SQL; 在使用Select或DML操作是产生隐式游标。 隐式游标的属性值永远死最新执行的SQL语句。 --隐式游标同样具有显示游标的属性 %ISOPEN :判断游标是否打开。返回 boolean 类型。 %FOUND :检测是否提取到有效的数据。返回 boolean 类型。 %NOTFOUND :与%FOUND 效果相反。 %ROWCOUNT :累计到目前位置游标提取到的数据行数。 使用隐式游标属性时: SQL%FOUND