DECLARE inventory_too_low EXCEPTION; ---其他声明语句 BEGIN . . IF order_rec.qty>inventory_rec.qty THEN RAISE inventory_too_low; END IF . . EXCEPTION WHEN inventory_too_low THEN order_rec.staus:='backordered'; replenish_inventory(inventory_nbr=> inventory_rec.sku,min_amount=>order_rec.qty-inventory_rec.qty); END;
EXCEPTION WHEN exception_name THEN Code for handing exception_name [WHEN another_exception THEN Code for handing another_exception] [WHEN others THEN code for handing any other exception.]
WHEN inventory_too_low THEN order_rec.staus:='backordered'; replenish_inventory(inventory_nbr=> inventory_rec.sku,min_amount=>order_rec.qty-inventory_rec.qty); WHEN discontinued_item THEN --code for discontinued_item processing WHEN zero_divide THEN --code for zero_divide WHEN OTHERS THEN --code for any other exception END;
BEGIN DECLARE bad_credit; BEGIN RAISE bad_credit; --发生异常,控制转向; EXCEPTION WHEN bad_credit THEN dbms_output.put_line('bad_credit'); END;
--bad_credit异常处理后,控制转到这里 EXCEPTION WHEN OTHERS THEN --控制不会从bad_credit异常转到这里 --因为bad_credit已被处理 END;
当异常发生时,在块的内部没有该异常处理器时,控制将转到或传播到上一层块的异常处理部分。
BEGIN DECLARE ---内部块开始 bad_credit; BEGIN RAISE bad_credit; --发生异常,控制转向; EXCEPTION WHEN ZERO_DIVIDE THEN --不能处理bad_credite异常 dbms_output.put_line('divide by zero error'); END --结束内部块
--控制不能到达这里,因为异常没有解决; --异常部分
EXCEPTION WHEN OTHERS THEN --由于bad_credit没有解决,控制将转到这里 END;
BEGIN executable statements BEGIN today DATE:='SYADATE'; --ERRROR BEGIN --内部块开始 dbms_output.put_line('this line will not execute'); EXCEPTION WHEN OTHERS THEN --异常不会在这里处理 END;--内部块结束
DECLARE inventory_too_low EXCEPTION; ---其他声明语句 BEGIN . . IF order_rec.qty>inventory_rec.qty THEN RAISE inventory_too_low; END IF . . EXCEPTION WHEN inventory_too_low THEN order_rec.staus:='backordered'; replenish_inventory(inventory_nbr=> inventory_rec.sku,min_amount=>order_rec.qty-inventory_rec.qty); END;
EXCEPTION WHEN exception_name THEN Code for handing exception_name [WHEN another_exception THEN Code for handing another_exception] [WHEN others THEN code for handing any other exception.]
WHEN inventory_too_low THEN order_rec.staus:='backordered'; replenish_inventory(inventory_nbr=> inventory_rec.sku,min_amount=>order_rec.qty-inventory_rec.qty); WHEN discontinued_item THEN --code for discontinued_item processing WHEN zero_divide THEN --code for zero_divide WHEN OTHERS THEN --code for any other exception END;
BEGIN DECLARE bad_credit; BEGIN RAISE bad_credit; --发生异常,控制转向; EXCEPTION WHEN bad_credit THEN dbms_output.put_line('bad_credit'); END;
--bad_credit异常处理后,控制转到这里 EXCEPTION WHEN OTHERS THEN --控制不会从bad_credit异常转到这里 --因为bad_credit已被处理 END;
当异常发生时,在块的内部没有该异常处理器时,控制将转到或传播到上一层块的异常处理部分。
BEGIN DECLARE ---内部块开始 bad_credit; BEGIN RAISE bad_credit; --发生异常,控制转向; EXCEPTION WHEN ZERO_DIVIDE THEN --不能处理bad_credite异常 dbms_output.put_line('divide by zero error'); END --结束内部块
--控制不能到达这里,因为异常没有解决; --异常部分
EXCEPTION WHEN OTHERS THEN --由于bad_credit没有解决,控制将转到这里 END;
BEGIN executable statements BEGIN today DATE:='SYADATE'; --ERRROR BEGIN --内部块开始 dbms_output.put_line('this line will not execute'); EXCEPTION WHEN OTHERS THEN --异常不会在这里处理 END;--内部块结束