Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

execute immediate in for loop

710208Aug 13 2012 — edited Aug 30 2012
Dear concerned,

I have one function in a package (databse 11g) with following code.
As listed, looping a table TASK_LIST to execute each task after confirming that it is not
already executed (by querying TASK_DONE table).

Problem I have encountered is , at times same task get executed more than once even if I am counter checking
with variable "mSUCCEED". Please guide me in this regard.


Unnikrishnan Nair.

=============
CODE LISTING:
=============
BEGIN
FOR L IN (SELECT * FROM TASK_LIST WHERE ISACTIVE = 1 )
LOOP
SELECT COUNT(*) INTO mSUCCEEDED FROM TASK_DONE WHERE TASKNAME = L.TASKNAME AND STATUS = 'DONE' ;
IF MSUCCEEDED = 0 THEN
STA := 'BEGIN '||CHR(10)
||' :mRESULT := BANK_EOD_NEW.'||L.TASKSNAME||'(:2,:3,:pErrMsg); '||CHR(10)
||'END;';
EXECUTE IMMEDIATE STA USING OUT mRESULT,IN pIDDATE,IN pHOMEBRANCH,OUT pErrMsg;
IF mRESULT = 0 THEN
pErrMsg := 'TASK '||L.TASKSNAME||' ERROR : '||pErrMsg;
ROLLBACK;
RETURN 0;
ELSE
INSERT INTO TASK_DONE (TASKNAME,STATUS,PROCESS,MKRUSR,MKRDATE,MKRBRH,MKRNODE,MKRTIME)
VALUES (mTEMP,'DONE','PREEOD',TRIM(pMKRUSR),pMKRDATE,pMKRBRH,TRIM(pMKRNODE),Systimestamp);

COMMIT;
END IF;
END IF;
END LOOP;
RETURN 1;
EXCEPTION
WHEN OTHERS THEN
pErrMsg := SQLERRM;
ROLLBACK;
RETURN 0;
END;

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 27 2012
Added on Aug 13 2012
10 comments
537 views