2009년 8월 16일 일요일

Exception

SQL> begin

2 dbms_output.put_line(3/1);

3 dbms_output.put_line(3/0);

4 end;

5 /

3

begin

*

ERROR at line 1:

ORA-01476: divisor is equal to zero

ORA-06512: at line 3

   

SQL> begin

2 dbms_output.put_line(3/1);

3 dbms_output.put_line(3/0);

4 exception

5 when others then

6 dbms_output.put_line('err');

7 end;

8 /

3

err

   

PL/SQL procedure successfully completed.

   

   

SQL> begin

2 dbms_output.put_line(3/1);

3 dbms_output.put_line(3/0);

4 exception

5 when ZERO_DIVIDE then

6 dbms_output.put_line('Divided by zero');

7 when others then

8 dbms_output.put_line(SQLERRM);

9 dbms_output.put_line(SQLCODE);

10 end;

11 /

3

Divided by zero

   

PL/SQL procedure successfully completed.

   

SQL>

SQL> declare

2 e emp%rowtype;

3 begin

4 dbms_output.put_line(3/1);

5 select * into e from emp where sal=3000;

6 dbms_output.put_line(e.ename || '''s sal is ' || e.sal);

7 exception

8 when TOO_MANY_ROWS then

9 dbms_output.put_line('More than One Row');

10 when others then

11 dbms_output.put_line(SQLERRM);

12 dbms_output.put_line(SQLCODE);

13 end;

14 /

3

More than One Row

   

PL/SQL procedure successfully completed.

   

댓글 없음:

댓글 쓰기