I really appreciate your help.
Please look at the code below. How can I replace the code below in to direct update then retriveing data and process, then update multiple rows for combination of three column in where clause.
The loop is going backword. as cursor in desending. Values are calculated with formula for multiple rows one by one.
One SKU, MULTIPLE SOTORE for one SKU and UNIQUE YEARWEEKKEY FOR EACH SKU AND SOTRE.
so if i pass one SKU AND SORE it WILL update atlear 10 to 50 rows for each COMBINATION OF SKU and STORE depending upon how many week. max in 50 week.
Please Please guide me.
Code:Procedure SP_930_End_Of_Week_OH_up ( pSKU In SS_SKU_Store_Week.SKU%Type, pStore In SS_SKU_Store_Week.Store_Num%Type) Is VARIABLEs...... Cursor OpportunityRating_Cursor Is SELECT /*+ index (SS_SKU_Store_Week SS_SKU_STR_WK_PK )*/ Opportunity_Rating, End_Of_Week_On_Hand, Decode(PSW_Flag, 0, 0, Distributed_Planned_Sales) DistributedPlannedSales FROM SS_SKU_Store_Week WHERE SKU = pSKU AND Store_Num = pStore ORDER BY Year_Week_Key Desc; BEGIN OPEN OpportunityRating_Cursor; LOOP FETCH OpportunityRating_Cursor bulk collect into vsku,vstore,vyearweekkey, vOpertunityRating,vOnHand, vdistributedSales limit 200 ; FOR i in vsku.first..vsku.last LOOP IF vOpertunityRating(i) Is Not Null Then vOpRat(v_idx):=case vforwardsales when 0 then 1 else Round(vOnHand(i)/ vForwardSales, 4) end; vsku_1.extend; vstore_1.extend; vyearweekkey_1.extend; vsku_1(v_idx) :=vsku(i); vstore_1(v_idx) :=vstore(i); vyearweekkey_1(v_idx):=vyearweekkey(i); v_idx :=v_idx+1; vForwardSales := 0; END IF; vForwardSales := vForwardSales + vdistributedSales(i); END LOOP;; FORALL i in 1..vOpRat.count update /*+ index (SS_SKU_Store_Week SS_SKU_STR_WK_PK )*/SS_SKU_Store_Week SET Opportunity_Rating = vOpRat(i) Where sku =vsku_1(i) and store_num =vstore_1(i) and year_week_key=vyearweekkey_1(i); EXIT WHEN OpportunityRating_Cursor%NOTFOUND; END LOOP; CLOSE OpportunityRating_Cursor; COMMITt; Exception When OTHERS Then Null; End SP_930_End_Of_Week_OH_up;




Reply With Quote