Oracle
 sql >> Datenbank >  >> RDS >> Oracle

PL/SQL FOR LOOP IMPLIZIERTER CURSOR

Sie verwenden INTO nicht mit einem impliziten Cursor:

    DECLARE
        emp_dept_id employees.department_id%TYPE;
        emp_emp_id employees.employee_id%TYPE;
        emp_last_name employees.last_name%TYPE;
        v_count number DEFAULT 0;
    BEGIN
        FOR i IN (SELECT DISTINCT department_id, department_name
            FROM departments)
        LOOP
            --v_COUNT := v_COUNT + 1;
            DBMS_OUTPUT.PUT_LINE('HELLO'||i.department_id||' '||i.department_name);
            FOR j IN (SELECT employee_id, last_name
                INTO emp_emp_id, emp_last_name
                FROM employees)
                --WHERE department_id=i.department_id)
            LOOP
                DBMS_OUTPUT.PUT_LINE(emp_emp_id||' '||emp_last_name);
                v_COUNT := v_COUNT + 1;
            END LOOP;
        END LOOP;
        DBMS_OUTPUT.PUT_LINE(v_COUNT);
    END;
    /