본문 바로가기
🖥Web/🔥DB & SQL

[SQL] SQL의 예외처리

by 후누스 토르발즈 2020. 3. 20.
반응형

 

 

create or replace procedure porc_exception1
is
    n_i number(10):=0;
begin
    n_i:='김유신';
    exception
        when invalid_number then
            DBMS_OUTPUT.PUT_LINE('잘못된 숫자값에 대한 에러 이다.');
        when value_error then
            DBMS_OUTPUT.PUT_LINE('잘못된 데이터값에 대한 에러 이다.');
        when others then
            DBMS_OUTPUT.PUT_LINE('잘못된 숫자나 데이터값은 아니다.');
end;

 

xec porc_exception1; 실행시 '잘못된 데이터값에 대한 에러 이다.' 가 출력된다.

 

 

create or replace procedure proc_errormsg
is
    err_num number;
    err_msg varchar2(100);
    n_i number(10, 3):=0;
begin
    n_i := 120/0;
    exception
    when others then
        err_num:=SQLCODE;
        err_msg:=substr(SQLERRM, 1, 100);
        DBMS_OUTPUT.PUT_LINE('에러코드:'||err_num);
        DBMS_OUTPUT.PUT_LINE('에러내용:'||err_msg);
end;

 

exec proc_errormsg를 실행시

'에러코드:-1476 '
'에러내용:ORA-01476: 제수가 0 입니다' 라고 출력된다.

 

 

반응형

'🖥Web > 🔥DB & SQL' 카테고리의 다른 글

[Sql] Tablespace(테이블스페이스)란?  (0) 2020.06.07
[Sql] SQL Cursor  (0) 2020.03.20
[SQL] 프로시저(procedure)와 declare 차이  (0) 2020.03.20
[SQL] 프로토콜에서 procedure 생성  (0) 2020.03.17
[SQL]MySql - 2 고급  (0) 2020.01.05