##  Using PL/SQL loops to speed up long-running SQL updates


    UPDATE ACCOUNT_TOTALS A 
    SET CURRENT_EXP = CURRENT_EXP + ( SELECT DAILY_EXP
                                       FROM  TRANSACTION T
                                       WHERE T.ACC_NO = A.ACC_NO )
    WHERE EXISTS ( SELECT 'X'
                   FROM   TRANSACTION T
                   WHERE  T.ACC_NO = A.ACC_NO  );


##  Can be written as :

    DECLARE
        CURSOR READ_TRAN  IS
        SELECT ACC_NO, DAILY_EXP
        FROM   TRANSACTION;
        --
        ACC_NO_STORE      NUMBER (6);
        DAILY_EXP_STORE   NUMBER (9,2);
    BEGIN
        OPEN READ_TRAN;
        LOOP
            FETCH READ_TRAN INTO ACC_NO_STORE, DAILY_EXP_STORE; 
            EXIT WHEN READ_TRAN%NOTFOUND;
            --
            UPDATE ACCOUNT_TOTALS A 
            SET    CURRENT_EXP = CURRENT_EXP + DAILY_EXP_STORE
            WHERE  ACC_NO      = ACC_NO_STORE ;
        END LOOP;
     END;
