我有带有 Cursor 和 fetch 的 LOOP 语句,但我想要“FOR LOOP”。
DECLARE
emp_rec employees%ROWTYPE;
CURSOR Cur_emp IS
SELECT *
FROM employees
order by employees.last_name asc;
BEGIN
OPEN Cur_emp;
LOOP
FETCH Cur_emp INTO emp_rec;
exit when Cur_emp%notfound;
dbms_output.put_line(‘Employee Name–>’|| emp_rec.LAST_NAME);
END LOOP;
CLOSE Cur_emp;
END;
我想喜欢:
DECLARE
emp_rec employees%ROWTYPE;
CURSOR Cur_emp IS
SELECT *
FROM employees
order by employees.last_name asc;
BEGIN
FOR item IN Cur_emp
LOOP
FETCH Cur_emp INTO emp_rec;
exit when Cur_emp%notfound;
dbms_output.put_line(‘Employee Name–>’|| emp_rec.LAST_NAME);
END LOOP;
END;
/
这不起作用,因为FETCH Cur_emp INTO emp_rec INVALID CURSOR ORA-01001