如果找到正确的用法,我在使用For in循环中的行在Oracle表中插入行时遇到了问题。
错误用法: - 仅插入一行,因为它没有增加
DECLARE ASSET_CLAIM_STAGE_ID NUMBER := tblAssetClaimStage_ID_SEQ.NextVal;
BEGIN
FOR SI IN 1..STAGEID LOOP
INSERT INTO tblAssetClaimStage (assetClaimStageID, assetID, claimstageID, createDateTime)
SELECT ASSET_CLAIM_STAGE_ID, IN_ASSETID, SI, IN_SOLDDATE FROM DUAL WHERE NOT EXISTS (SELECT ASSETID
FROM tblAssetClaimStage
WHERE assetID = IN_ASSETID AND
claimstageID = SI);
END LOOP;
正确使用:
FOR SI IN 1..STAGEID LOOP
INSERT INTO tblAssetClaimStage (assetClaimStageID, assetID, claimstageID, createDateTime)
SELECT tblAssetClaimStage_ID_SEQ.NextVal, IN_ASSETID, SI, IN_SOLDDATE FROM DUAL WHERE NOT EXISTS (SELECT ASSETID
FROM tblAssetClaimStage
WHERE assetID = IN_ASSETID AND
claimstageID = SI);
END LOOP;
COMMIT;
还有其他更好的方法吗?
答案 0 :(得分:0)
您可以使用forall
来避免循环。但是,如果你真的需要循环,你的例子看起来很好。