我正在尝试在 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;
提前谢谢!!阿伦