日期:2014-05-17 浏览次数:20807 次
CREATE OR PROCEDURE DF_ID IS V_SUBG3EFID NUMBER; CURSOR CUR IS( SELECT NAME FROM TEST T); BEGIN FOR CUR_RESULT IN CUR LOOP BEGIN SELECT ID INTO V_SUBID FROM STUDENT WHERE ROWNUM = 1 AND NAME1 = CUR_RESULT.NAME; EXCEPTION WHEN NO_DATA_FOUND THEN NULL; END; UPDATE TEST T SET T.OID = V_SUBID WHERE T.NAME1 = CUR_RESULT.NAME; END LOOP; COMMIT; END DF_ID;
------解决方案--------------------
--或者 CREATE OR PROCEDURE DF_ID IS V_SUBG3EFID NUMBER; CURSOR CUR IS( SELECT NAME FROM TEST T); BEGIN FOR CUR_RESULT IN CUR LOOP BEGIN SELECT ID INTO V_SUBID FROM STUDENT WHERE ROWNUM = 1 AND NAME1 = CUR_RESULT.NAME; EXCEPTION WHEN NO_DATA_FOUND THEN GO TO LABLE1; END; UPDATE TEST T SET T.OID = V_SUBID WHERE T.NAME1 = CUR_RESULT.NAME; <<LABLE1>> END LOOP; COMMIT; END DF_ID;