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.

Update statement not working inside function

abisheksivaJan 26 2016 — edited Jan 26 2016

Logic of this function:

**************************

From invoice system we will post the data to ERP system once invoice is processed this function will update the erp invoice number and process flag to invoice system table.

CREATE OR REPLACE FUNCTION ERP_TO_MOPS_INV_UPD RETURN NUMBER IS

/* Function for update the invoice number  processed status back to invoice table */

FRETVAL NUMBER:=0;

BEGIN

  

   FOR I IN (SELECT PISH_ID,PISH_INV_NO FROM PH_INVOICE_SMRY_HDR  WHERE ERP_STGFLG='S') LOOP

  

     FOR J IN(SELECT INVOICE_NO FROM XXMO_AR_INVOICE_ARC  WHERE REFERENCE_NO=I.PISH_INV_NO AND REFERENCE_DOC_ID=I.PISH_ID AND NVL(MO_STATUS,'N')='N') LOOP

    

        UPDATE PH_INVOICE_SMRY_HDR SET ERP_INVOICE_NO=J.INVOICE_NO,ERP_STGFLG='P' WHERE PISH_ID=I.PISH_ID AND PISH_INV_NO=I.PISH_INV_NO;

        IF SQL%NOTFOUND THEN

           FRETVAL:=1003;

        END IF;       

       

        UPDATE XXMO_AR_INVOICE_ARC  SET MO_STATUS='P' WHERE  REFERENCE_DOC_ID=I.PISH_ID AND REFERENCE_NO=I.PISH_INV_NO;

        IF SQL%NOTFOUND THEN

           FRETVAL:=1004;

        END IF;

      

      END LOOP;     

    END LOOP;

    RETURN FRETVAL;

  

   exception when others then

   FRETVAL:=-1;

END ERP_TO_MOPS_INV_UPD; 

when i try to run like this values are not get updated. But when i run this code using anonymous block its working. Anyone please help me

declare

ret number:=0;

begin

ret:=ERP_TO_MOPS_INV_UPD;

DBMS_OUTPUT.PUT_LINE('RETURN VALUE'|| RET);

end;

This post has been answered by BrunoVroman on Jan 26 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 23 2016
Added on Jan 26 2016
3 comments
498 views