千家信息网

2011-11-21 未捕获异常

发表于:2025-01-25 作者:千家信息网编辑
千家信息网最后更新 2025年01月25日,http://www.itpub.net/thread-1499223-17-1.html167楼下列哪些选项在执行之后会导致未捕获的异常:ORA-06502: PL/SQL: numeric or
千家信息网最后更新 2025年01月25日2011-11-21 未捕获异常

http://www.itpub.net/thread-1499223-17-1.html

167楼

下列哪些选项在执行之后会导致未捕获的异常:

ORA-06502: PL/SQL: numeric or value error: number precision too large

(A)

DECLARE   l_number   NUMBER (2) := 100;BEGIN   DBMS_OUTPUT.put_line (l_number);END;/
SQL> DECLARE  2     l_number   NUMBER (2) := 100;  3  BEGIN  4     DBMS_OUTPUT.put_line (l_number);  5  END;  6  /DECLARE   l_number   NUMBER (2) := 100;BEGIN   DBMS_OUTPUT.put_line (l_number);END;ORA-06502: PL/SQL: 数字或值错误 :  数值精度太高ORA-06512: 在 line 2SQL>

(B)

DECLARE   l_number   NUMBER (2) := 100;BEGIN   DBMS_OUTPUT.put_line (l_number);EXCEPTION   WHEN OTHERS   THEN      DBMS_OUTPUT.put_line ('ERROR');END;/
SQL> DECLARE  2     l_number   NUMBER (2) := 100;  3  BEGIN  4     DBMS_OUTPUT.put_line (l_number);  5  EXCEPTION  6     WHEN OTHERS  7     THEN  8        DBMS_OUTPUT.put_line ('ERROR');  9  END; 10  /DECLARE   l_number   NUMBER (2) := 100;BEGIN   DBMS_OUTPUT.put_line (l_number);EXCEPTION   WHEN OTHERS   THEN      DBMS_OUTPUT.put_line ('ERROR');END;ORA-06502: PL/SQL: 数字或值错误 :  数值精度太高ORA-06512: 在 line 2SQL>

(C)

CREATE OR REPLACE PACKAGE plch_pkgIS   FUNCTION get_number      RETURN NUMBER;END;/CREATE OR REPLACE PACKAGE BODY plch_pkgIS   g_date     DATE;   g_number   NUMBER (2) := 100;   FUNCTION get_number      RETURN NUMBER   IS   BEGIN      RETURN g_number;   END;BEGIN   g_date := SYSDATE;EXCEPTION   WHEN OTHERS   THEN      DBMS_OUTPUT.put_line ('ERROR');END;/DECLARE   l_number   NUMBER (2) := plch_pkg.get_number;BEGIN   DBMS_OUTPUT.put_line (l_number);END;/
SQL> CREATE OR REPLACE PACKAGE plch_pkg  2  IS  3     FUNCTION get_number  4        RETURN NUMBER;  5  END;  6  /Package createdSQL> CREATE OR REPLACE PACKAGE BODY plch_pkg  2  IS  3     g_date     DATE;  4     g_number   NUMBER (2) := 100;  5    6     FUNCTION get_number  7        RETURN NUMBER  8     IS  9     BEGIN 10        RETURN g_number; 11     END; 12  BEGIN 13     g_date := SYSDATE; 14  EXCEPTION 15     WHEN OTHERS 16     THEN 17        DBMS_OUTPUT.put_line ('ERROR'); 18  END; 19  /Package body createdSQL> DECLARE  2     l_number   NUMBER (2) := plch_pkg.get_number;  3  BEGIN  4     DBMS_OUTPUT.put_line (l_number);  5  END;  6  /DECLARE   l_number   NUMBER (2) := plch_pkg.get_number;BEGIN   DBMS_OUTPUT.put_line (l_number);END;ORA-06502: PL/SQL: 数字或值错误 :  数值精度太高ORA-06512: 在 "YOGA.PLCH_PKG", line 4ORA-06512: 在 line 2SQL>

(D)

CREATE OR REPLACE PACKAGE plch_pkgIS   g_number   NUMBER (2) := 100;END;/DECLARE   l_number   NUMBER (2) := plch_pkg.g_number;BEGIN   DBMS_OUTPUT.put_line (l_number);END;/
SQL> CREATE OR REPLACE PACKAGE plch_pkg  2  IS  3     g_number   NUMBER (2) := 100;  4  END;  5  /Package createdSQL> DECLARE  2     l_number   NUMBER (2) := plch_pkg.g_number;  3  BEGIN  4     DBMS_OUTPUT.put_line (l_number);  5  END;  6  /DECLARE   l_number   NUMBER (2) := plch_pkg.g_number;BEGIN   DBMS_OUTPUT.put_line (l_number);END;ORA-06502: PL/SQL: 数字或值错误 :  数值精度太高ORA-06512: 在 "YOGA.PLCH_PKG", line 3ORA-06512: 在 line 4SQL>

答案在172楼

2011-11-21 答案:ABCD

如果异常发生在BEGIN之前,比如DECLARE部分或PACKAGE的变量初始化部分,那么这个异常就不会被当前块的EXCEPTION捕获,而是继续向外传播。

0