存储过程中避免抛出无数据的异常的写法

在存储过程中使用select into赋值的时候,假如无数据的话,会抛出ORA-01403异常,解决办法如下:

BEGIN SELECT ROUND(TO_NUMBER(T.SINGLE_SOURCE_AMOUNT) / TO_NUMBER(T.TOTAL_AMOUNT), 2) * 100 INTO VAR_SINGLE_AMOUNT_PER FROM CS_PURCHASE_AMOUNT_YEAR T WHERE TO_NUMBER(T.TOTAL_AMOUNT) != 0 AND T.TOTAL_AMOUNT IS NOT NULL AND T.CREATE_YEAR = VAR_LAST_YEAR AND T.SUPPLIER_CODE = VAR_SUPPLIER_CODE; EXCEPTION WHEN NO_DATA_FOUND THEN VAR_SINGLE_AMOUNT_PER := 0; END;

 

posted on 2017-11-07 16:55  锟斤拷锟斤拷  阅读(331)  评论(0编辑  收藏  举报

导航