oracle procedure 儲存過程輸入及輸出in out示例

wisdomone1發表於2012-02-14
 真是搞笑至極.因久未編寫儲存過程.竟然今天出笑話.TCBS業務系統中涉及的儲存過程諸如errnbr及errmsg輸出引數,僅在儲存過程出錯異常exception才會有值.我竟然跑到編寫儲存過程的同事處詢問此事.以為人家的問題.後回來一測試.
 一定要加強學習.從事IT行業.真是一日不練.技藝生啊.


 附上測試程式碼,供備記
--a為輸入引數
--b為輸出引數
--測試目的:如果a有值,則b將無值;否則如果a無值,則b有值

create or replace procedure test_out(a in integer,b out integer)
as
none_a exception;--定義判斷輸入引數a是否有值的異常
begin
if (a=1) then
 null;--當輸入引數有值,什麼也不作
end if;

if (a is null) then --當輸入引數無值
raise none_a; --觸發儲存過程定義的異常none_a
end if;
exception  --由exception定義具體的異常處理程式碼
when none_a then --exception由諸多when then節構成
b:=888; --捕獲了異常none_a,輸出引數b為888
when others then
 b:=111;
end;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-716285/,如需轉載,請註明出處,否則將追究法律責任。

相關文章