存储过程中避免抛出无数据的异常的写法
在存储过程中使用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;
生活不止眼前的苟且,还有诗和远方。。。