日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
PostgreSQL程序中批量綁定時怎么使用saveexceptions記錄錯誤數(shù)據(jù)

這篇文章主要講解了“PostgreSQL程序中批量綁定時怎么使用save exceptions記錄錯誤數(shù)據(jù)”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“PostgreSQL程序中批量綁定時怎么使用save exceptions記錄錯誤數(shù)據(jù)”吧!

成都創(chuàng)新互聯(lián)公司主營嵊州網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件定制開發(fā),嵊州h5微信小程序開發(fā)搭建,嵊州網(wǎng)站營銷推廣歡迎嵊州等地區(qū)企業(yè)咨詢

一:利用scott下的emp表構(gòu)造數(shù)據(jù)

--構(gòu)造數(shù)據(jù)
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對應(yīng)的異常
  Excp_Bulk_Errors Exception;
  --將異常和錯誤號關(guān)聯(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ù)據(jù)”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對PostgreSQL程序中批量綁定時怎么使用save exceptions記錄錯誤數(shù)據(jù)這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!


本文名稱:PostgreSQL程序中批量綁定時怎么使用saveexceptions記錄錯誤數(shù)據(jù)
轉(zhuǎn)載來源:http://www.dlmjj.cn/article/ipieei.html