我想在oracle遊標中使用連接,它是失敗的。任何人都可以給我一些幫助,以解決光標下面的問題。是否有可能在oracle遊標中使用連接?加入oracle遊標
CURSOR items_cursor IS
SELECT a.*, b.* FROM
(SELECT DataId, Name, VersionNum, OwnerId, SubType, LEVEL Lev FROM DTree
START WITH ParentId = 2000 CONNECT BY PRIOR DataId= ABS(ParentId)
)a,
(
SELECT o.DataId, o.Permissions OwnerPerm, p.Permissions PublicPerm FROM DTreeAcl o, DTreeAcl p WHERE
o.DataId=p.Dataid AND o.AclType=1 AND p.AclType=3 AND (o.Permissions != 130 OR p.Permissions != 36995)
)b
WHERE a.Lev >= 1 AND a.Lev <= 3 AND a.DataId = b.DataId;
上面的查詢工作正常,沒有光標。
這個遊標然後在for循環中使用。
BEGIN
FOR item IN items_cursor LOOP
rowCnt := rowCnt + 1;
-- Some update and insert stmts
IF rowCnt = 1000 THEN
COMMIT;rowCnt := 0;
END IF;
END LOOP;
這裏是我的全部程序代碼..
CREATE OR REPLACE PROCEDURE "RMNAUSR"."PERMS_UPDATE_UPTO_LEVEL3" IS
rowCnt INT := 0;
ownerPerm INT := 130;
publicPerm INT := 36995;
permUpdated BOOLEAN:= FALSE;
excludeSubTypes VARCHAR(30) := '201,202,203';
CURSOR items_cursor IS
(SELECT a.*, b.* FROM
(SELECT DataId, Name, VersionNum, OwnerId, SubType, LEVEL Lev FROM DTree
START WITH ParentId = 2000 CONNECT BY PRIOR DataId= ABS(ParentId)
)a,
(
SELECT o.DataId, o.Permissions OwnerPerm, p.Permissions PublicPerm FROM DTreeAcl o, DTreeAcl p WHERE
o.DataId=p.Dataid AND o.AclType=1 AND p.AclType=3 AND (o.Permissions != 130 OR p.Permissions != 36995)
)b
WHERE a.Lev >= 1 AND a.Lev <= 3 AND a.DataId = b.DataId);
BEGIN
FOR item IN items_cursor LOOP
rowCnt := rowCnt + 1;
permUpdated := FALSE;
-- some insert and update stmts here
IF rowCnt = 1000 THEN
COMMIT;
rowCnt := 0;
END IF;
END LOOP;
COMMIT;
EXCEPTION WHEN OTHERS THEN raise_application_error(-20001,SQLERRM);
END PERMS_UPDATE_UPTO_LEVEL3;
在Adavance謝謝! Arun
當然可以使用Oracle遊標連接 - 具體失敗的是什麼? – antlersoft 2013-04-10 16:42:21
我沒有收到任何具體或可理解的錯誤消息。我正在使用DBVisualizer,它返回下面的msg> 11:34:33 [@CALL - 0行,0.000秒] [錯誤代碼:6550,SQL狀態:65000] ORA-06550:第1行第7列: PLS-00905:對象RMNAUSR.PERMS_UPDATE_UPTO_LEVEL3無效 ORA-06550:第1行,第7列: PL/SQL:語句被忽略 – 2013-04-10 16:44:18
聽起來像存儲過程中包含光標的其他地方存在問題。 – antlersoft 2013-04-10 16:50:25