当前位置: 代码迷 >> Oracle开发 >> 如何找到隐式cursor最后一条记录
  详细解决方案

如何找到隐式cursor最后一条记录

热度:26   发布时间:2016-04-24 07:42:04.0
怎么找到隐式cursor最后一条记录
for c in (select * from student) loop
我想取到最后一条记录。怎么求?

------解决方案--------------------
定义个recored记录:
declare
...
l_r student%ROWTYPE;
...
begin
for c in (select * from student) loop 
...
l_r:=c;
end loop;
--l_r就是最后的记录,这里处理
....
end;
/

引用楼主 cinderella_m 的帖子:
for c in (select * from student) loop
我想取到最后一条记录。怎么求?

------解决方案--------------------
SQL code
-- 换一种思路可以用可变数组:   set serveroutput on   declare        type tabletype1 is table of varchar2(9) index by binary_integer;        table1 tabletype1;   begin        table1(1):='成都市';        table1(2):='北京市';        table1(3):='青岛市';        dbms_output.put_line('总记录数:'||to_char(table1.count));        dbms_output.put_line('第一条记录:'||table1.first);        dbms_output.put_line('最后条记录:'||table1.last);        dbms_output.put_line('第二条的前一条记录:'||table1.prior(2));        dbms_output.put_line('第二条的后一条记录:'||table1.next(2));    end;
------解决方案--------------------
SQL code
SQL> set serveroutput on;SQL> SQL> declare  2    cursor cu is  3      select ename from emp where deptno = 10;  4    type enametype is table of varchar2(10);  5    etype enametype;  6  begin  7    open cu;  8    fetch cu bulk collect  9      into etype; 10    dbms_output.put_line(etype(cu%rowcount)); 11    close cu; 12  end; 13  /MILLERPL/SQL procedure successfully completed
  相关解决方案