错误
ORA-06504: PL/SQL: 结果集变量或查询的返回类型不匹配
ORA-06512: 在line 9
代码如下:
declare
type cur is ref cursor;
yy cur;
xx emp.ename%type;begin
open yy for select a2.* from (select * from (select emp.ename,rownum rn from emp order by sal) a1 where a1.rn>7) a2 where a2.rn<9;
fetch yy into xx;
while yy%found loop
dbms_output.put_line('显示'||xx);end loop;
close yy;
end;其中 select a2.* from (select * from (select emp.ename,rownum rn from emp order by sal) a1 where a1.rn>7) a2 where a2.rn<9; 此句是从emp表中,选出位置序号是8的记录。

解决方案 »

  1.   

    select a2.* from (select * from (select emp.ename,rownum rn from emp order by sal) a1 where a1.rn>7) a2 where a2.rn<9;最里面有一个 rownum ,外面再select * 就把这个也查出来了,和你定义的 xx自然不一样了。
      

  2.   

    rownum 本身是伪劣,不存在的,只有你在select 以后才会分配 
    rownum 每次分配都是从1开始分配的
      

  3.   

    select a2.* from (
    select * from (
    select emp.ename,row_number() over(order by sal )rn from emp
    ) a1 where a1.rn>7
    ) a2 where a2.rn<9; 
      

  4.   

    rownum 只能用<=,不能用>。
      

  5.   

    rownum的用法的确有点奥妙
    参考 http://www.cnblogs.com/xiekeli/archive/2009/04/02/1643329.html
      

  6.   

    a2:select * from (select emp.ename,rownum rn from emp order by sal) a1 where a1.rn>7
    它的查询结果是2列数据
    而select a2.* from ...之后的结果应该也是2列数据
    也就是说游标是指向2列数据的
    fetch yy into xx(xx使用xx emp.ename%type定义的应该是1列数据)把2的数据指向赋值给1列的接收变量?这样可以吗?我也是刚刚开始学Oracle的~若理解不当还请见谅!