Im updating the table GLRS.TBL_GLRS_GT_PRC_FEED with the enriched data based on the OPICS_TYPE value usng two approaches
The other mapping tables are GLRS.TBL_GLRS_OPICS_RULES and GLRS.TBL_GLRS_OPICS_TYPE
------------------------------------------------
The two approaches are as below
-- Approach 1
---------------------
-- Approach 2
Please let me know if approach
The other mapping tables are GLRS.TBL_GLRS_OPICS_RULES and GLRS.TBL_GLRS_OPICS_TYPE
Code:
CREATE TABLE GLRS.TBL_GLRS_OPICS_RULES
(
TBL_GLRS_OPICS_RULES_ID NUMBER(38,0) not null,
TBL_GLRS_OPICS_TYPE_ID NUMBER(38,0) not null,
TBL_GLRS_OPICS_PROD_ID NUMBER(38,0) not null,
TBL_AGG_PRODUCT_LINE_ID NUMBER(38,0) not null,
TBL_GLRS_MAR_CONF_ID NUMBER(38,0) not null,
TBL_GLRS_PROD_LINE_TYPE_ID NUMBER(38,0) not null,
TBL_GLRS_PROD_LINE_SUB_TYPE_ID NUMBER(38,0) not null,
CREATED_BY VARCHAR2(20) not null,
CREATED_DATETIME TIMESTAMP(6) not null,
UPDATED_BY VARCHAR2(20) not null,
UPDATED_DATETIME TIMESTAMP(6) not null,
CONSTRAINT PKY_TBL_GLRS_OPICS_RULES_ID PRIMARY KEY(TBL_GLRS_OPICS_RULES_ID)
);
CREATE TABLE GLRS.TBL_GLRS_OPICS_TYPE
(
TBL_GLRS_OPICS_TYPE_ID NUMBER(38,0) not null,
OPICS_TYPE VARCHAR2(2) not null,
TYPE_DESCRIPTION VARCHAR2(15) not null,
CREATED_BY VARCHAR2(20) not null,
CREATED_DATETIME TIMESTAMP(6) not null,
UPDATED_BY VARCHAR2(20) not null,
UPDATED_DATETIME TIMESTAMP(6) not null,
CONSTRAINT PKY_TBL_GLRS_OPICS_TYPE_ID PRIMARY KEY(TBL_GLRS_OPICS_TYPE_ID)
);
------------------------------------------------
The two approaches are as below
-- Approach 1
Code:
/*Qry to select MAR based on rules. This will be included as inner select qry in the below base qry.*/
V_MAR_QRY := ' (SELECT CF.TBL_GLRS_MU_ID FROM GLRS.TBL_GLRS_INTERIM_MAR_CONF CF WHERE CF.TBL_GLRS_MAR_CONF_ID = PR.TBL_GLRS_MAR_CONF_ID) TBL_GLRS_MU_ID ';
/*Base query for selecting rules from the OPICS rules table.*/
V_QUERY := ' SELECT TBL_AGG_PRODUCT_LINE_ID,TBL_GLRS_PROD_LINE_TYPE_ID,TBL_GLRS_PROD_LINE_SUB_TYPE_ID,' ||
V_MAR_QRY ||
' FROM GLRS.TBL_GLRS_OPICS_RULES PR WHERE PR.TBL_GLRS_OPICS_TYPE_ID = :1 ';
FOR V_DATA IN (SELECT T.OPICS_TYPE FROM GLRS.TBL_GLRS_GT_OPICS_FEED T)
LOOP
BEGIN
/*Retrieve opics_type id */
SELECT C.TBL_GLRS_OPICS_TYPE_ID
INTO V_OPICS_TYPE_ID
FROM GLRS.TBL_GLRS_OPICS_TYPE C
WHERE C.OPICS_TYPE = V_DATA.OPICS_TYPE;
IF (V_OPICS_TYPE_ID IS NOT NULL) THEN
/*Retreive MAR and Product line id on the basis of Pool Code*/
EXECUTE IMMEDIATE V_QUERY
INTO V_PROD_LINE_ID, V_PROD_LINE_TYPE_ID, V_PROD_LINE_SUB_TYPE_ID, V_MU_ID
USING V_OPICS_TYPE_ID;
/*Update MAR and Product Line ID against each record.*/
UPDATE GLRS.TBL_GLRS_GT_PRC_FEED F
SET F.TBL_AGG_PRODUCT_LINE_ID = V_PROD_LINE_ID,
F.TBL_GLRS_PROD_LINE_TYPE_ID = V_PROD_LINE_TYPE_ID,
F.TBL_GLRS_PROD_LINE_SUB_TYPE_ID = V_PROD_LINE_SUB_TYPE_ID,
F.TBL_GLRS_MU_ID = V_MU_ID
WHERE F.OPICS_TYPE = V_DATA.OPICS_TYPE;
END IF;
EXCEPTION
WHEN OTHERS THEN
NULL;
END ;
END LOOP;
-- Approach 2
Code:
CURSOR c_get_opics_prodtype
IS
SELECT b.opics_type, b.prod FROM GLRS.TBL_GLRS_GT_OPICS_FEED b;
TYPE c_get_opics_prodtype_type IS TABLE OF c_get_opics_prodtype%rowtype;
opics_prodtype c_get_opics_prodtype_type;
OPEN c_get_opics_prodtype;
LOOP
FETCH c_get_opics_prodtype BULK COLLECT INTO opics_prodtype limit 200;
FOR i in 1..opics_prodtype.count
/*Retreive MAR and Product line id on the basis of Pool Code*/
SELECT PR.TBL_AGG_PRODUCT_LINE_ID,
PR.TBL_GLRS_PROD_LINE_TYPE_ID,
PR.TBL_GLRS_PROD_LINE_SUB_TYPE_ID,
(SELECT CF.TBL_GLRS_MU_ID
FROM GLRS.TBL_GLRS_INTERIM_MAR_CONF CF
WHERE CF.TBL_GLRS_MAR_CONF_ID = PR.TBL_GLRS_MAR_CONF_ID) TBL_GLRS_MU_ID
INTO V_PROD_LINE_ID,
V_PROD_LINE_TYPE_ID,
V_PROD_LINE_SUB_TYPE_ID,
V_MU_ID,
FROM GLRS.TBL_GLRS_INTERIM_MAR_CONF CF , GLRS.TBL_GLRS_OPICS_RULES PR
WHERE PR.TBL_GLRS_MAR_CONF_ID = CF.TBL_GLRS_MAR_CONF_ID AND
PR.TBL_GLRS_OPICS_TYPE_ID IN (SELECT C.TBL_GLRS_OPICS_TYPE_ID
FROM GLRS.TBL_GLRS_OPICS_TYPE C
WHERE C.OPICS_TYPE IN ('BY','RG','FI') ;
LOOP
IF opics_prodtype(i).OPICS_TYPE = 'BY' THEN
UPDATE GLRS.TBL_GLRS_GT_OPICS_FEED G
SET G.TBL_AGG_PRODUCT_LINE_ID = V_PROD_LINE_ID,
G.TBL_GLRS_PROD_LINE_TYPE_ID = V_PROD_LINE_TYPE_ID,
G.TBL_GLRS_PROD_LINE_SUB_TYPE_ID = V_PROD_LINE_SUB_TYPE_ID,
G.TBL_GLRS_MU_ID = V_MU_ID
ELSIF ((opics_prodtype(i).OPICS_TYPE = 'RG' AND TRIM(opics_prodtype(i).PROD) = "DEPO" )OR (opics_prodtype(i).OPICS_TYPE = 'FI' AND TRIM(opics_prodtype(i).PROD) = "DEPO") AND (M_DATE = Null or M_DATE = V_AS_OF_DATE + 1) )THEN
UPDATE GLRS.TBL_GLRS_GT_OPICS_FEED G
SET G.TBL_AGG_PRODUCT_LINE_ID = V_PROD_LINE_ID,
G.TBL_GLRS_PROD_LINE_TYPE_ID = V_PROD_LINE_TYPE_ID,
G.TBL_GLRS_PROD_LINE_SUB_TYPE_ID = V_PROD_LINE_SUB_TYPE_ID,
G.TBL_GLRS_MU_ID = V_MU_ID
END IF;
END LOOP;
EXIT WHEN c_get_opics_prodtype%NOTFOUND;
END LOOP;
CLOSE c_get_opics_prodtype;
Please let me know if approach