'PLSQL- UPDATE USING CURSOR CAUSING RECURSIVE LOOP

DECLARE
CURSOR emp_cur
IS
    SELECT ename,empno,dname,sal
    FROM emp3
    WHERE dname='SALES';
BEGIN 
    FOR emp_rec IN emp_cur
    LOOP
        IF emp_rec.dname='SALES' THEN
            UPDATE emp3
            SET sal = sal + sal*0.10
            WHERE empno = emp_rec.empno;
        END IF;
    END LOOP;
END;

*Cause: An attempt was made to go more than the specified number of recursive SQL levels.

*Action: Remove the recursive SQL, possibly a recursive trigger.

I am getting this error while trying to update using cursor. What changes should I do?



Solution 1:[1]

The code u wrote doesnt make any sense to me, 1st why would u use pls sql cursor instead of simple update..set..where sql command, 2nd why loop 'for loop' through cursor when u can simply write: for i in (select statement), 3rd this line: where empno = emp_rec.empno; is nonsensical, u are looping through cursor u are not joining tables.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Toni Antunovi?