我希望从存储过程中返回每个部门的前四名最高工资以及deptno和dname。 当deptno不包括在内时没有错误但是 当包括deptno我得到一个错误无效的数字。 ORA-01722:无效的号码 这是代码
create or replace procedure tpro2(dno in emp.deptno%type,dnum out dept.deptno%type, name out emp.ename%type, sal out emp.sal%type,dname out dept.dname%type, cur out sys_refcursor)
is begin
open cur for select ename , sal, dname, dept.deptno from (select * from emp order by sal desc)emp, dept where emp.deptno=dept.deptno and emp.deptno=dno and rownum<=4;
end tpro2;
/
declare
dnum dept.deptno%type;
name emp.ename%type;
sal emp.sal%type;
dname dept.dname%type;
cur sys_refcursor;
begin
tpro2(&dno,dnum,name,sal,dname,cur);
loop
fetch cur into dnum,name,sal,dname;
exit when cur%notfound;
dbms_output.put_line(dnum||' '||name||' '||sal||' '||dname);
end loop;
close cur;
end;
/
请帮助!!!
答案 0 :(得分:0)
open cur for select ename, sal, dname, dept.deptno
fetch cur into dnum, name, sal, dname;
你觉得这里没有什么可疑的吗? :)
答案 1 :(得分:0)
我会使用window functions来获取您需要的信息,而无需编写存储过程:
SELECT ename, sal, dname, deptno
RANK() OVER (PARTITION BY deptno ORDER BY sal DESC) "Rank"
FROM emp e inner join dept d using (deptno)