首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

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

2012-01-02 
怎么找到隐式cursor最后一条记录for c in (select * from student) loop我想取到最后一条记录。怎么求?[解

怎么找到隐式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 

热点排行