您好,登錄后才能下訂單哦!
http://www.itpub.net/thread-1499223-7-1.html
70樓
下列的哪些程序塊在執(zhí)行之后會(huì)顯示:"Trapped!"
注意:當(dāng)你試圖把字符串 "13-DEC-2004 6:56 PM" 使用掩碼 "DD-MON-YYYY HH:MI:SS" 轉(zhuǎn)換成日期型時(shí),Oracle 會(huì)拋出 ORA-01858 錯(cuò)誤。
(A)
DECLARE e1 EXCEPTION; PRAGMA EXCEPTION_INIT (e1, -1858); BEGIN DBMS_OUTPUT.put_line ( TO_DATE ('13-DEC-2004 6:56 PM' , 'DD-MON-YYYY HH:MI:SS')); EXCEPTION WHEN e1 THEN DBMS_OUTPUT.put_line ('Trapped!'); END; /
SQL> DECLARE 2 e1 EXCEPTION; 3 PRAGMA EXCEPTION_INIT (e1, -1858); 4 BEGIN 5 DBMS_OUTPUT.put_line ( 6 TO_DATE ('13-DEC-2004 6:56 PM' 7 , 'DD-MON-YYYY HH:MI:SS')); 8 EXCEPTION 9 WHEN e1 10 THEN 11 DBMS_OUTPUT.put_line ('Trapped!'); 12 END; 13 / DECLARE e1 EXCEPTION; PRAGMA EXCEPTION_INIT (e1, -1858); BEGIN DBMS_OUTPUT.put_line ( TO_DATE ('13-DEC-2004 6:56 PM' , 'DD-MON-YYYY HH:MI:SS')); EXCEPTION WHEN e1 THEN DBMS_OUTPUT.put_line ('Trapped!'); END; ORA-01843: 無效的月份 ORA-06512: 在 line 5 SQL>
(B)
DECLARE e1 EXCEPTION; PRAGMA EXCEPTION_INIT (e1, -1858); BEGIN DECLARE e2 EXCEPTION; PRAGMA EXCEPTION_INIT (e2, -1858); BEGIN DBMS_OUTPUT.put_line ( TO_DATE ('13-DEC-2004 6:56 PM' , 'DD-MON-YYYY HH:MI:SS')); END; EXCEPTION WHEN e1 THEN DBMS_OUTPUT.put_line ('Trapped!'); END; /
SQL> DECLARE 2 e1 EXCEPTION; 3 PRAGMA EXCEPTION_INIT (e1, -1858); 4 BEGIN 5 DECLARE 6 e2 EXCEPTION; 7 PRAGMA EXCEPTION_INIT (e2, -1858); 8 BEGIN 9 DBMS_OUTPUT.put_line ( 10 TO_DATE ('13-DEC-2004 6:56 PM' 11 , 'DD-MON-YYYY HH:MI:SS')); 12 END; 13 EXCEPTION 14 WHEN e1 15 THEN 16 DBMS_OUTPUT.put_line ('Trapped!'); 17 END; 18 / DECLARE e1 EXCEPTION; PRAGMA EXCEPTION_INIT (e1, -1858); BEGIN DECLARE e2 EXCEPTION; PRAGMA EXCEPTION_INIT (e2, -1858); BEGIN DBMS_OUTPUT.put_line ( TO_DATE ('13-DEC-2004 6:56 PM' , 'DD-MON-YYYY HH:MI:SS')); END; EXCEPTION WHEN e1 THEN DBMS_OUTPUT.put_line ('Trapped!'); END; ORA-01843: 無效的月份 ORA-06512: 在 line 9 SQL>
(C)
DECLARE e1 EXCEPTION; PRAGMA EXCEPTION_INIT (e1, -1858); BEGIN DECLARE e2 EXCEPTION; PRAGMA EXCEPTION_INIT (e2, -1858); BEGIN DBMS_OUTPUT.put_line ( TO_DATE ('13-DEC-2004 6:56 PM' , 'DD-MON-YYYY HH:MI:SS')); END; EXCEPTION WHEN e2 THEN DBMS_OUTPUT.put_line ('Trapped!'); END; /
SQL> DECLARE 2 e1 EXCEPTION; 3 PRAGMA EXCEPTION_INIT (e1, -1858); 4 BEGIN 5 DECLARE 6 e2 EXCEPTION; 7 PRAGMA EXCEPTION_INIT (e2, -1858); 8 BEGIN 9 DBMS_OUTPUT.put_line ( 10 TO_DATE ('13-DEC-2004 6:56 PM' 11 , 'DD-MON-YYYY HH:MI:SS')); 12 END; 13 EXCEPTION 14 WHEN e2 15 THEN 16 DBMS_OUTPUT.put_line ('Trapped!'); 17 END; 18 / DECLARE e1 EXCEPTION; PRAGMA EXCEPTION_INIT (e1, -1858); BEGIN DECLARE e2 EXCEPTION; PRAGMA EXCEPTION_INIT (e2, -1858); BEGIN DBMS_OUTPUT.put_line ( TO_DATE ('13-DEC-2004 6:56 PM' , 'DD-MON-YYYY HH:MI:SS')); END; EXCEPTION WHEN e2 THEN DBMS_OUTPUT.put_line ('Trapped!'); END; ORA-06550: 第 14 行, 第 9 列: PLS-00201: 必須聲明標(biāo)識(shí)符 'E2' ORA-06550: 第 0 行, 第 0 列: PL/SQL: Compilation unit analysis terminated SQL>
(D)
DECLARE e1 EXCEPTION; BEGIN DECLARE PRAGMA EXCEPTION_INIT (e1, -1858); BEGIN DBMS_OUTPUT.put_line ( TO_DATE ('13-DEC-2004 6:56 PM' , 'DD-MON-YYYY HH:MI:SS')); END; EXCEPTION WHEN e1 THEN DBMS_OUTPUT.put_line ('Trapped!'); END; /
SQL> DECLARE 2 e1 EXCEPTION; 3 BEGIN 4 DECLARE 5 PRAGMA EXCEPTION_INIT (e1, -1858); 6 BEGIN 7 DBMS_OUTPUT.put_line ( 8 TO_DATE ('13-DEC-2004 6:56 PM' 9 , 'DD-MON-YYYY HH:MI:SS')); 10 END; 11 EXCEPTION 12 WHEN e1 13 THEN 14 DBMS_OUTPUT.put_line ('Trapped!'); 15 END; 16 / DECLARE e1 EXCEPTION; BEGIN DECLARE PRAGMA EXCEPTION_INIT (e1, -1858); BEGIN DBMS_OUTPUT.put_line ( TO_DATE ('13-DEC-2004 6:56 PM' , 'DD-MON-YYYY HH:MI:SS')); END; EXCEPTION WHEN e1 THEN DBMS_OUTPUT.put_line ('Trapped!'); END; ORA-06550: 第 2 行, 第 4 列: PLS-00700: 'E1' 的 PRAGMA EXCEPTION_INIT 必須在同一個(gè)聲明部分中的異常錯(cuò)誤聲明之后 ORA-06550: 第 5 行, 第 7 列: PL/SQL: Item ignored SQL>
結(jié)果有出入,設(shè)置語言為英文后重跑
SQL> alter session set nls_language='american'; Session altered SQL> SQL> DECLARE 2 e1 EXCEPTION; 3 PRAGMA EXCEPTION_INIT (e1, -1858); 4 BEGIN 5 DBMS_OUTPUT.put_line ( 6 TO_DATE ('13-DEC-2004 6:56 PM' 7 , 'DD-MON-YYYY HH:MI:SS')); 8 EXCEPTION 9 WHEN e1 10 THEN 11 DBMS_OUTPUT.put_line ('Trapped!'); 12 END; 13 / Trapped! PL/SQL procedure successfully completed SQL>
SQL> alter session set nls_language='american'; Session altered SQL> SQL> SQL> DECLARE 2 e1 EXCEPTION; 3 PRAGMA EXCEPTION_INIT (e1, -1858); 4 BEGIN 5 DECLARE 6 e2 EXCEPTION; 7 PRAGMA EXCEPTION_INIT (e2, -1858); 8 BEGIN 9 DBMS_OUTPUT.put_line ( 10 TO_DATE ('13-DEC-2004 6:56 PM' 11 , 'DD-MON-YYYY HH:MI:SS')); 12 END; 13 EXCEPTION 14 WHEN e1 15 THEN 16 DBMS_OUTPUT.put_line ('Trapped!'); 17 END; 18 / Trapped! PL/SQL procedure successfully completed SQL>
SQL> alter session set nls_language='american'; Session altered SQL> SQL> SQL> DECLARE 2 e1 EXCEPTION; 3 PRAGMA EXCEPTION_INIT (e1, -1858); 4 BEGIN 5 DECLARE 6 e2 EXCEPTION; 7 PRAGMA EXCEPTION_INIT (e2, -1858); 8 BEGIN 9 DBMS_OUTPUT.put_line ( 10 TO_DATE ('13-DEC-2004 6:56 PM' 11 , 'DD-MON-YYYY HH:MI:SS')); 12 END; 13 EXCEPTION 14 WHEN e2 15 THEN 16 DBMS_OUTPUT.put_line ('Trapped!'); 17 END; 18 / DECLARE e1 EXCEPTION; PRAGMA EXCEPTION_INIT (e1, -1858); BEGIN DECLARE e2 EXCEPTION; PRAGMA EXCEPTION_INIT (e2, -1858); BEGIN DBMS_OUTPUT.put_line ( TO_DATE ('13-DEC-2004 6:56 PM' , 'DD-MON-YYYY HH:MI:SS')); END; EXCEPTION WHEN e2 THEN DBMS_OUTPUT.put_line ('Trapped!'); END; ORA-06550: line 14, column 9: PLS-00201: identifier 'E2' must be declared ORA-06550: line 0, column 0: PL/SQL: Compilation unit analysis terminated SQL>
SQL> alter session set nls_language='american'; Session altered SQL> SQL> SQL> DECLARE 2 e1 EXCEPTION; 3 BEGIN 4 DECLARE 5 PRAGMA EXCEPTION_INIT (e1, -1858); 6 BEGIN 7 DBMS_OUTPUT.put_line ( 8 TO_DATE ('13-DEC-2004 6:56 PM' 9 , 'DD-MON-YYYY HH:MI:SS')); 10 END; 11 EXCEPTION 12 WHEN e1 13 THEN 14 DBMS_OUTPUT.put_line ('Trapped!'); 15 END; 16 / DECLARE e1 EXCEPTION; BEGIN DECLARE PRAGMA EXCEPTION_INIT (e1, -1858); BEGIN DBMS_OUTPUT.put_line ( TO_DATE ('13-DEC-2004 6:56 PM' , 'DD-MON-YYYY HH:MI:SS')); END; EXCEPTION WHEN e1 THEN DBMS_OUTPUT.put_line ('Trapped!'); END; ORA-06550: line 2, column 4: PLS-00700: PRAGMA EXCEPTION_INIT of E1 must follow declaration of its exception in the same declarative part ORA-06550: line 5, column 7: PL/SQL: Item ignored SQL>
答案AB(設(shè)置語言為英文,則答案AB;如語言為中文,答案均不正確)
答案說明74樓
A: 正確捕獲-1858異常 B: 內(nèi)層也定義了-1858但是沒有捕獲,所以外層仍然能夠捕獲到 C: 內(nèi)層的定義在外層是不可見的,會(huì)報(bào)PLS-00201: identifier 'E2' must be declared D: PRAGMA EXCEPTION_INIT必須和EXCEPTION定義在同一層DECLARE中: PLS-00700: PRAGMA EXCEPTION_INIT of E1 must follow declaration of its exception in the same declarative part
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。