Reputation: 312
Hi everyone I am a bit new to PL/SQL so am a bit confused. I have a Cursor called rec
and while looping through it I have two nested IF statements.
CURSOR Cur IS
SELECT Mil.Id,
Mil.Record_Num,
Mil.Status,
Mil.file_processed,
Mil.Updated_By
FROM status_log mil
WHERE Mil.file_processed != 'Processed'
For Update of Mil.file_processed;
FOR Rec IN Cur LOOP
IF (Rec.status = 'Ready' OR Rec.status = 'Go') THEN
IF Length(Rec.Zip) = 5 AND
(Substr(Rec.Zip, 1, 3) = '303' OR
Substr(Rec.Zip, 1, 3) = '304' ) THEN
l_state:= 'ATL';
END IF;
UPDATE status_log mil
SET file_processed = 'Processed'
WHERE current of cur
END IF;
COMMIT;
END LOOP;
Now whenever the cursor has one record that satisfies the second IF
(i.e Zip is 5 in length and the code starts with 303 or 304) it doesnt hit the update
statement anymore for that records and all record after that. I even tried using the EXIT
statement after the logic in the IF
loop but to no avail. What am I doing wrong?
Upvotes: 0
Views: 4072
Reputation: 17643
it is possible that status_log rows to update are locked by another session. You can query the blocking_session column of v$session view.
the "code to do something" is doing something.
file_processed
but lock the row for the column status
. I've not tested, but that could be an issue.Upvotes: 1
Reputation: 48131
IFs aren't loops. This may actually be an important point since you say you've tried using an EXIT
, and the purpose of that statement is to exit from the immediately enclosing loop. In this case, that means the loop over the cursor (unless possibly your "code to do something" includes other loops). So any EXIT
you put in there would have caused the entire loop to terminate.
If it doesn't execute the update, then the "code to do something" is either (a) using an explicit command that affects the flow control, such as EXIT
, CONTINUE
, or GOTO
, or (b) encountering an error that is causing control to switch to some exception handler somewhere.
If the execute is updating but failing, then you should be seeing an error -- unless, again, there is an exception handler somewhere that is hiding it from you.
Upvotes: 3
Reputation: 91
Check to see if your CURSOR
definition includes or excludes the table status_log
... That could be the problem.
Upvotes: 0