错误
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的记录。
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的记录。
rownum 每次分配都是从1开始分配的
select * from (
select emp.ename,row_number() over(order by sal )rn from emp
) a1 where a1.rn>7
) a2 where a2.rn<9;
参考 http://www.cnblogs.com/xiekeli/archive/2009/04/02/1643329.html
它的查询结果是2列数据
而select a2.* from ...之后的结果应该也是2列数据
也就是说游标是指向2列数据的
fetch yy into xx(xx使用xx emp.ename%type定义的应该是1列数据)把2的数据指向赋值给1列的接收变量?这样可以吗?我也是刚刚开始学Oracle的~若理解不当还请见谅!