CREATE OR REPLACE PROCEDURE proc1(p_tab_id IN number) AS /*CREATE A CURSOR TO GET ALL THE ROWS FOR THE SPECIFIED TABLE */ CURSOR table_info_cur IS SELECT * FROM (SELECT source_tab FROM table_info WHERE tab_id = p_tab_id);-- Holds all table data into the cursor. /*CREATE A TABLE COLLECTION TYPE TO HOLD THIS CURSOR INFORMATION SO THAT ALL UPDATES OPERATIONS CAN BE PERFORMED ON THIS RECORDSET ITSELF*/ TYPE TableSet IS TABLE OF table_info_cur%ROWTYPE; table_info_set TableSet; -- Holds set of rows for the given table. /*CREATE CURSOR FOR THE RULES TABLE TO GET ALL RULES ASSOCIATED WITH THE PARTICULAR TABLE*/ CURSOR rules_info_cur IS SELECT * FROM rules_info WHERE tab_id = p_tab_id; rules_info_rec rules_info_cur%ROWTYPE; v_counter number :=0; /* TO KEEP TRACK OF PRIORITIES */ query_str VARCHAR2(500); /* FOR DYNAMIC SQL STRING */ BEGIN /*With one query, we bring all the relevant data into the collection of records.*/ SELECT * BULK COLLECT INTO table_info_set FROM (SELECT source_tab FROM table_info WHERE tab_id = p_tab_id); /*Now we can process the data by examining the collection, or passing it to a separate procedure, instead of writing a loop to FETCH each row.*/ FOR i IN table_info_set.FIRST .. table_info_set.LAST LOOP /* FOR EVERY ROW OF THE COLLECTION LOOP THROUGH THE RULES TABLE AND GET ALL THE RULES N COLUMNS ASSOCIATED WITH THE TABLE.*/ IF rules_info_cur%ISOPEN THEN CLOSE rules_info_cur; END IF; OPEN rules_info_cur; LOOP FETCH rules_info_cur into rules_info_rec; EXIT WHEN rules_info_cur%NOTFOUND; /* INITIALISE THE COUNTER TO THE CURRENT RULE PRIORITY */ v_counter := rules_info_rec.priority; /*IF the flag from the rules_info table is "N" for NULL RECORDS DIRECTLY Apply the rule picked up from the rules table to the current column and row record of the table.*/ IF rules_info_rec.flag = 'N' THEN table_info_set(i).rules_info_rec.col_name := rules_info_rec.relation_function; /***** I CAN GET THE COLUMN NAME FROM THE rules_info_rec CURSOR RECORD, BUT HOW DO I USE IT WITH THE COLLECTION AND AFTER APPLYING IT TO TEH COLLECTION I NEED TO INSERTY THE ENTIRE COLLECTION INTO A NEW TABLE ****/ END LOOP; END LOOP; END proc1; END;