可以在IF()內使用Cursor Then條件?我試着下面的代碼 但它的工作..任何人都幫我解決這個問題?IF()內的光標然後
我的代碼是:
BEGIN
IF EXISTS
((select '1'
from cttest c
where not exists(
select 1 from cof o where c.createddate > add_months(sysdate,-6) and c.ctid not in (
o.ctid , o.bctid, o.lc1, o.lc2, o.sslc1,o.sslc2)
) and c.lastupdated is null and c.lastupdatedcof is null)) THEN
begin
cursor ctdelete
IS
select ctid,ctname from cttest c
where not exists(
select 1 from cof o where c.createddate > add_months(sysdate,-6) and c.ctid not in (
o.ctid , o.bctid, o.lc1, o.lc2, o.sslc1,o.sslc2)
) and c.lastupdated is null and c.lastupdatedcof is null
end;
FOR reDel_audit IN ctdelete
LOOP
insert into ctaudit (ctid,ctname,v_IsDeleted,null,sysdate);
COMMIT;
END LOOP;
END;
錯誤是:
錯誤(22,8):PLS-00103:出現符號 「ctdelete」 在需要下列之一時::=。 (@%;
你甚至需要第一光標?您的FOR LOOP將評估記錄的存在。 – Drumbeg
@Drumbeg基於遊標的結果,我需要遍歷每一行並插入到ctaudit表中。 –
那麼,遊標看起來幾乎和我一樣。不要以爲你需要根據相同的標準在循環之前檢查記錄的存在。 – Drumbeg