回覆列表
-
1 # 使用者2062070693800
-
2 # 使用者7364316064609
create or replace procedure proc_test( strAge in string, strName in string, ret_code out string, v_error_message out string) is
begin
declare
strsql varcchar(1024);
v_error_desc varcchar(1024);
begin
v_error_desc :="student";
strsql :="select name from student where age=100";
execute immediate strsql using strAge ;
v_error_desc :="teacher";
strsql :="select age from teacher where name=jill";
execute immediate strsql using strName ;
ret_code:=0;
v_error_desc :="OK";
v_error_message:="OK";
EXCEPTION
WHEN OTHERS THEN
ret_code := sqlcode;
v_error_desc := "錯誤位置:" || v_error_desc;
v_error_message := sqlerrm;
rollback;
end;
end proc_cancel_digital_id;
如果資料庫是10g及以上版本,可以使用dbms_utility.format_error_backtrace(),這個函式能夠返回錯誤行,可以套用以下格式:
create or replace procedure prc_test(引數) is
v_no number;
begin
select no into v_no from zrp;
exception
when others then
dbms_output.put_line("SQL CODE:"||sqlcode||chr(10)||
sqlerrm||chr(10)||
dbms_utility.format_error_backtrace());
end;
這樣寫的好處是,當程式發成異常,唄exception捕獲後,就會打印出錯誤資訊及發生錯誤的行號