ORA-01427 单行子查询返回多于一个行

报错前pl/sql语句:

UPDATE "DEVELOP"."PRODUCE_PLAN_NEED_PRODUCT" A
SET A.REMAIN_AMOUNT=A.AMOUNT-
(SELECT BAMOUNT
 FROM "DEVELOP"."VIEW_PLAN" B
  WHERE B.PRODUCE_PLAN_ID=A.PRODUCE_PLAN_ID
  AND B.PRODUCT_ID=A.PRODUCT_ID);

修改后pl/sql语句:

UPDATE "DEVELOP"."PRODUCE_PLAN_NEED_PRODUCT" A
SET A.REMAIN_AMOUNT=A.AMOUNT-
(SELECT BAMOUNT
 FROM "DEVELOP"."VIEW_PLAN" B
  WHERE B.PRODUCE_PLAN_ID=A.PRODUCE_PLAN_ID
  AND B.PRODUCT_ID=A.PRODUCT_ID AND rownum =1);

 

原因:同一条件子查询返回多条语句,必加rownum限制

 

你可能感兴趣的:(开发中遇到错误)