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.] |
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;--内部块结束 EXCEPTION WHEN OTHERS THEN 处理异常 END |
DECLARE order_too_old EXCEPTION; BEGIN RAISE order_too_old; EXCEPTION WHEN order_too_old THEN DECLARE file_handle UTL_FILE.FILE_TYPE; BEGIN --open file file_handle:=UTL_FILE.FOPEN (location=>'/ora01/app/oracle/admin/test/utlsir' ,filename=>'error.log' .open_mode=>'W'); --write error stack UTL_FILE.PUT_LINE(filehandle, DBMS_UTILITY.FORMAT_ERROR_STACK); --write the call stack UTL_FILE.PUT_LINE(filehandle, DBMS_UTILITY.FORMAT_CALL_STACK); --close error log UTL_FILE.FCLOSE(file_handle); RAISE; --re-raise the exception END 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.] |
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;--内部块结束 EXCEPTION WHEN OTHERS THEN 处理异常 END |
DECLARE order_too_old EXCEPTION; BEGIN RAISE order_too_old; EXCEPTION WHEN order_too_old THEN DECLARE file_handle UTL_FILE.FILE_TYPE; BEGIN --open file file_handle:=UTL_FILE.FOPEN (location=>'/ora01/app/oracle/admin/test/utlsir' ,filename=>'error.log' .open_mode=>'W'); --write error stack UTL_FILE.PUT_LINE(filehandle, DBMS_UTILITY.FORMAT_ERROR_STACK); --write the call stack UTL_FILE.PUT_LINE(filehandle, DBMS_UTILITY.FORMAT_CALL_STACK); --close error log UTL_FILE.FCLOSE(file_handle); RAISE; --re-raise the exception END END |
新闻热点
疑难解答