题目:
使用循环和游标实现,查询部门编号为10的员工信息,将查询结果按照员工编号从大到小的顺序排列,输出倒数第二行记录。
我的代码:
declare
empler emp%rowtype;
i number:=0;
n number;
cursor emp_2 is select * from emp where deptno=10 order by empno desc;
begin
select count(*) into n from emp where deptno=10;
open emp_2;
fetch emp_2 into empler;
loop
i:=i+1;
if i=n-1
then
dbms_output.put_line('hh');
end if;
fetch emp_2 into empler;
exit when emp_2%notfound;
end loop;
end;
错误报告:
ORA-06550: 第 7 行, 第 50 列:
PL/SQL: ORA-00911: 无效字符
ORA-06550: 第 7 行, 第 3 列:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
请问哪里出错了?用这样的方法行的通吗?不行的话用什么方法?