I have been trying to work on a solution to update a column status on my table. I have a table called customer_balance_tb with the below structure and it is populated every day with data:
- Code: Select all
create table CUSTOMER_BALANCE_TB
(
MSISDN VARCHAR2(20) not null,
BALANCE NUMBER,
DATE_N VARCHAR2(8) not null,
STATUS VARCHAR2(2) default 0,
COS NUMBER,
LOADDATE DATE,
EXPIRED_FLG VARCHAR2(20)
)
When the data is inserted in the table the status column is null as the status need to come from another table account_tb with the below structure
- Code: Select all
create table account_tb
(MSISDN VARCHAR2(20) not null,
STATUS Number
)
So the number of records that can exists in the customer_balance_tb table is over a million per day. Everyday i want to update the status in the customer_balance_tb table by checking the respective customer status in the account_tb table. when i do an update with the code below it takes extremely long to update the millions of records and when the procedure completes nothing was updated. See the procedure below that i created to update status field:
- Code: Select all
create or replace procedure custbal_update
is
CUR_DATE VARCHAR2(15) := TO_CHAR(SYSDATE,'DD-MON-YYYY');
CURSOR c_status IS
SELECT msisdn,status
FROM account_tb;
TYPE t_num_array IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
v_msisdn t_num_array;
v_status t_num_array;
v_row_count NUMBER := 0;
BEGIN
OPEN c_status;
LOOP
FETCH c_status
BULK COLLECT INTO v_msisdn, v_status
LIMIT 100;
EXIT WHEN c_status%NOTFOUND;
/* EXIT WHEN v_row_count = c_status%ROWCOUNT;
v_row_count := c_status%ROWCOUNT;*/
/* FOR i IN 1..v_msisdn.count LOOP
v_status(i) := v_status(i);
END LOOP; */
FORALL i IN 1..v_msisdn.count
UPDATE customer_balance_tb
SET status = v_status(i)
WHERE msisdn = v_msisdn(i)
and trunc(loaddate) = CUR_DATE;
END LOOP;
CLOSE c_status;
COMMIT;
END;
Kindly assist if i am missing out something here. Thanks alot for your support in advance.
Regards,
Selly