create or replace procedure Proc_1(P_IN_TABLE_NAME VARCHAR2)
AS
CURSOR T_FACT
IS
SELECT T_ID,T_VER,D_T_ID
from O_T_FACT
where T_ID is not null
and T_VER is not null;
TYPE call_tab IS TABLE OF O_T_FACT%rowtype;
BEGIN
IF P_IN_TABLE_NAME ='G_FACT' THEN
OPEN T_FACT;
LOOP
EXIT WHEN T_FACT%NOTFOUND ;
FETCH T_FACT BULK COLLECT INTO call_data_rec LIMIT no_of_rec;
EXIT WHEN call_data_rec.count = 0;
FOR j IN 1..call_data_rec.COUNT
loop
UPDATE G_FACT GL set
GL.T_ID = call_data_rec(j).T_ID,
GL.T_VER =call_data_rec(j).T_VER,
GL.TRANS_FLAG='Y'
WHERE GL.G_T_ID = call_data_rec(j).D_T_ID
AND GL.T_ID IS NULL
AND GL.T_VER IS NULL;
rec_count := rec_count + 1;
if mod(rec_count,10000) = 0 then
commit;
end if;
end loop;
end loop;
CLOSE T_FACT;
END IF;
End;
这个特定的过程需要很长时间,还有其他方法可以写吗?这可以在单个更新语句中完成吗?
正如下面所建议的,除了 PLS-00436 给出的错误之外,我已经厌倦了所有的事情:实施限制:无法引用 BULK In-BIND 记录表的字段
面向所有人的新代码
create or replace procedure Proc_update_T_ID(P_IN_TABLE_NAME VARCHAR2)
AS
no_of_rec number := 1000;
CURSOR T_and_V_FACT
IS
SELECT O_T_FACT.T_ID, O_T_FACT.T_VER, O_T_FACT.Downstream_T_ID, G_FACT.rowid row_id,
From O_T_FACT, G_FACT
WHERE O_T_FACT.T_ID IS NOT NULL AND G_FACT.G_T_ID = O_T_FACT.Downstream_T_ID
AND T_VER is not null
AND G_FACT.T_VER IS NULL;
TYPE call_tab IS TABLE OF T_and_V_FACT%rowtype index by binary_integer;
call_data_rec call_tab;
BEGIN
IF P_IN_TABLE_NAME ='G_FACT' THEN
IF T_and_V_FACT%ISOPEN THEN
CLOSE T_and_V_FACT;
END IF;
open T_and_V_FACT;
LOOP
FETCH T_and_V_FACT BULK COLLECT
INTO call_data_rec LIMIT no_of_rec;
FORALL j IN call_data_rec.FIRST .. call_data_rec.LAST
UPDATE G_FACT GL set
GL.T_ID = call_data_rec(j).T_ID,
GL.T_VER =call_data_rec(j).T_VER,
GL.TRANS_FLAG='Y'
WHERE GL.rowid = call_data_rec(j).row_id;
COMMIT;
call_data_rec.DELETE;
EXIT WHEN T_and_V_FACT%NOTFOUND;
END LOOP;
CLOSE T_and_V_FACT;
End if;
END Proc_1;