1、帶參數插入並帶返回值,異常信息
CREATE OR REPLACE PROCEDURE test_pro (v_id in int,v_name in varchar2,app_code out int,error_Msg out varchar) -- in 是輸入參數;out 輸出參數 IS BEGIN INSERT INTO proc_test (id,name) VALUES (v_id,v_name); --往表中插入一條數據 app_code:=8; --執行狀態碼,8 成功;9失敗 error_Msg:='執行成功'; --執行執行結果 commit; --提交事務 EXCEPTION rollback; --回滾提交的事務 when others then app_code:=9; --執行狀態碼,8 成功;9失敗 error_Msg:=SUBSTR(SQLERRM, 1, 200); --返回報錯信息 --存儲過程調用失敗,往存儲過程日志表追加一條記錄,方便以后查詢;第一個參數:調用存儲過程名,第二個參數:錯誤信息 INSERT INTO proc_error (proc_name,msg_error) VALUES ('test_pro',error_Msg); commit; --重新提交事務,記錄日志 END;
調用
--調用存儲過程 DECLARE app_code number; --聲明變量,用於接收狀態碼 msg_error varchar(200); --聲明變量,用於接收錯誤信息 BEGIN test_pro(2,'222',app_code,msg_error); dbms_output.put_line(app_code); --輸出狀態碼 dbms_output.put_line(msg_error); --輸出錯誤信息 END;