重慶分公司,新征程啟航
為企業(yè)提供網站建設、域名注冊、服務器等服務
為企業(yè)提供網站建設、域名注冊、服務器等服務
這篇文章主要講解了“PostgreSQL程序中批量綁定時怎么使用save exceptions記錄錯誤數(shù)據”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“PostgreSQL程序中批量綁定時怎么使用save exceptions記錄錯誤數(shù)據”吧!
成都創(chuàng)新互聯(lián)公司主營嵊州網站建設的網絡公司,主營網站建設方案,app軟件定制開發(fā),嵊州h5微信小程序開發(fā)搭建,嵊州網站營銷推廣歡迎嵊州等地區(qū)企業(yè)咨詢
--構造數(shù)據 Create Table t1 As Select * From scott.emp Where 1=2; Alter Table t1 Add Constraint pk_emp_empno Primary Key(empno); Alter Table t1 Modify(ename Not Null); Alter Table t1 Add Constraint chk_sql check(Sal >= 800); Create Table t2 As Select * FROM scott.emp; Insert Into t2 Select * FROM scott.emp Where empno In(7369,7499); Update t2 Set sal = 700 Where empno In(7521,7566); Update t2 Set ename = Null Where empno = 7698; Create Table t_error As Select * From scott.emp Where 1=2; Alter Table t_error Add(error_idx number,ErrorCode Varchar2(50));
--一次獲取所有ORA-24381錯誤的記錄 Declare --定義ORA-24381對應的異常 Excp_Bulk_Errors Exception; --將異常和錯誤號關聯(lián) Pragma Exception_Init(Excp_Bulk_Errors, -24381); --定義存儲Error Index和Error Code的變量 n_Err_Idx Number; Vc_Err_Code Varchar2(50); Cur_Ref_Emp Sys_Refcursor; Pi_Fetch_Limit Pls_Integer := 1000; Type Typ_Emp Is Table Of Emp%Rowtype Index By Binary_Integer; Typ_Emp_Rec Typ_Emp; Begin Open Cur_Ref_Emp For Select * From T2; --批量獲取 Fetch Cur_Ref_Emp Bulk Collect Into Typ_Emp_Rec Limit Pi_Fetch_Limit; --批量執(zhí)行 Forall i In 1 .. Typ_Emp_Rec.Count Save Exceptions Execute Immediate 'insert into t1 values(:empno,:ename,:job,:mgr,:hiredate,:sal,:comm,:deptno)' Using Typ_Emp_Rec(i).Empno, Typ_Emp_Rec(i).Ename, Typ_Emp_Rec(i).Job, Typ_Emp_Rec(i).Mgr, Typ_Emp_Rec(i).Hiredate, Typ_Emp_Rec(i).Sal, Typ_Emp_Rec(i).Sal, Typ_Emp_Rec(i).Deptno; Exception When Excp_Bulk_Errors Then --清空錯誤日志表 Execute Immediate 'delete from t_error'; For i In 1 .. Sql%Bulk_Exceptions.Count() Loop n_Err_Idx := Sql%Bulk_Exceptions(i).Error_Index; Vc_Err_Code := Sql%Bulk_Exceptions(i).Error_Code; Execute Immediate 'insert into t_error values(:empno,:ename,:job,:mgr,:hiredate,:sal,:comm,:deptno,:idx,:code)' Using Typ_Emp_Rec(n_Err_Idx).Empno, Typ_Emp_Rec(n_Err_Idx).Ename, Typ_Emp_Rec(n_Err_Idx).Job, Typ_Emp_Rec(n_Err_Idx).Mgr, Typ_Emp_Rec(n_Err_Idx).Hiredate, Typ_Emp_Rec(n_Err_Idx).Sal, Typ_Emp_Rec(n_Err_Idx).Sal, Typ_Emp_Rec(n_Err_Idx).Deptno, n_Err_Idx, Vc_Err_Code; End Loop; End;
感謝各位的閱讀,以上就是“PostgreSQL程序中批量綁定時怎么使用save exceptions記錄錯誤數(shù)據”的內容了,經過本文的學習后,相信大家對PostgreSQL程序中批量綁定時怎么使用save exceptions記錄錯誤數(shù)據這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關知識點的文章,歡迎關注!