oracle怎么獲取exception信息
通過如下代碼:
public static String getExceptionAllinformation(Exception ex){
String sOut = "";
StackTraceElement[] trace = ex.getStackTrace();
for (StackTraceElement s : trace) {
sOut += "\tat " + s + "\r\n";
}
return sOut;
}
擴展資料:注意事項
oracle存儲過程,可以通過sqlcode 獲取異常編碼、通過sqlerrm獲取異常信息。
例子:
create or replace procedure write2blob(p_id in number, --id
p_blob_data in blob,
p_msg out varchar2) --數據
is
v_lobloc blob; --目標blob
v_blob_data blob; --作為接受參數的字段,參數變量不能直接拿來賦值
v_amount binary_integer; --總長度
v_sub_length binary_integer; --一次讀取的最大長度,不超過32766
v_sub_blob blob; --一次讀取的子串
v_offt binary_integer; --游標
v_err_msg varchar2(1000);
v_id binary_integer; --要修改或新增的記錄ID
v_temp binary_integer; --臨時變量用于判斷是否有v_id對應的記錄begin
v_amount := length(p_blob_data);
v_blob_data := p_blob_data;
v_sub_length := 32767;
v_offt := 1;
v_id := p_id;
v_temp := 0; --execute immediate v_query_string into v_lobloc;
lect count(1) into v_temp from a where id = v_id; --查詢是否有v_id對應的記錄,并且賦值給v_te/*注意:無論是修改還是新增,blob字段都需要用empty_blob()進行初始化,否則后邊的blob內容,不能寫進表里面。
oracle exception問題續
--cursor定義為forupdate時,fetch的時候不能有commit及rollback命令的。
--否則會報ORA-01002:讀取違反順序錯誤
declare
cursormycurislect*fromscott.emp1forupdate;
excep_empexception;
excep_otherxception;
begin
forv_empinmycurloop
begin
--先檢查是否超過5000
ifv_emp.sal>5000then
raiexcep_emp;
endif;
--然后在更新
dbms_output.put_line(v_emp.ename||'調整前的工資為:'||v_emp.sal);
updatescott.emp1tsal=1.5*salwherecurrentofmycur;
dbms_output.put_line(v_emp.ename||'調整后的工資為:'||v_emp.sal*1.5);
exception
whenexcep_empthen
dbms_output.put_line('該員工的工資不能超過5000');
whenothersthen
--程序錯誤拋出異常停止運行
dbms_output.put_line('Error0:'||sqlerrm);
raiexcep_others;
end;
endloop;
--統一提交,
commit;
exception
whenexcep_othersthen
rollback;
whenothersthen
dbms_output.put_line('Error1:'||sqlerrm);
end;
oracle怎么獲取exception信息?
通過RAISE彈出框(調試時使用)
通過sqlcode , sqlerrm 這兩個內置變量來查看,
例如:DECLARE --聲明異常 some_kinds_of_err EXCEPTION; -- Exception to indicate an error condition v_ErrorCode NUMBER; -- Variable to hold the er..
為了提高存儲過程的健壯性,避免運行錯誤,當建立存儲過程時應包含異常處理部分.
Oracle.DataAccess.Client.OracleException ORA-12154: TNS: 無法解析指定的連接標識符
oracle 中的 exception when others then 捕獲異常 在db2中怎么寫
本文發布于:2023-02-28 18:59:00,感謝您對本站的認可!
本文鏈接:http://www.newhan.cn/zhishi/a/167759351650988.html
版權聲明:本站內容均來自互聯網,僅供演示用,請勿用于商業和其他非法用途。如果侵犯了您的權益請與我們聯系,我們將在24小時內刪除。
本文word下載地址:oracleexception.doc
本文 PDF 下載地址:oracleexception.pdf
| 留言與評論(共有 0 條評論) |