存储过程中使用dblink,碰到dblink死锁解决方案

CREATE OR REPLACE PROCEDURE synchronous_pm_t_material AS PRAGMA AUTONOMOUS_TRANSACTION; ---打开自动事务机制,此处的分号别忘了
     last_version VARCHAR2(14);
     current_version VARCHAR2(14);    
    
     CURSOR sync_row_cursor(p_last_version varchar2,p_current_version varchar2)
     IS
     SELECT OBJID,OBJVERSION,PART_NO AS MATERIAL_NO,DESCRIPTION AS MATERIAL_NAME,REQUISITION_NO,LINE_NO,STATE AS PROCESS_TYPE,1 AS AREA,
     REQUESTED_QTY AS AMOUNT,BUY_UNIT_MEAS AS UNIT,TYPE_DESIGNATION AS SPEC,DIM_QUALITY AS IMAGE_NO,ACCOUNTING_GROUP AS ACCOUNT,         
     REQUISITIONER_ORG AS ORG,CONTACT,BUYER_CODE,DEL_DES_CODE,NOTE_TEXT AS NOTES,VENDOR_NO                                               
     FROM GZB_EPMS_material WHERE OBJVERSION > p_last_version AND  OBJVERSION <= p_current_version
     UNION
     SELECT OBJID,OBJVERSION,PART_NO AS MATERIAL_NO,DESCRIPTION AS MATERIAL_NAME,REQUISITION_NO,LINE_NO,STATE AS PROCESS_TYPE,2 AS AREA,  
     REQUESTED_QTY AS AMOUNT,BUY_UNIT_MEAS AS UNIT,TYPE_DESIGNATION AS SPEC,DIM_QUALITY AS IMAGE_NO,ACCOUNTING_GROUP AS ACCOUNT,         
     REQUISITIONER_ORG AS ORG,CONTACT,BUYER_CODE,DEL_DES_CODE,NOTE_TEXT AS NOTES,VENDOR_NO
     FROM TG_EPMS_material WHERE OBJVERSION > p_last_version AND  OBJVERSION <= p_current_version;
 BEGIN
     SELECT last_SYNCHRONOUS_TIME INTO last_version FROM (SELECT (to_char(SYNCHRONOUS_TIME,'yyyymmddhhmiss')) AS last_SYNCHRONOUS_TIME FROM PM_T_SYNC_TIME  ORDER BY SYNCHRONOUS_TIME DESC) WHERE ROWNUM <= 1;
     SELECT to_char(SYSDATE,'yyyymmddhhmiss') INTO current_version FROM dual;
    
     FOR sync_row IN sync_row_cursor(last_version,current_version)
     LOOP   
       IF (fun_material_haved(sync_row.objid)=0) THEN
           INSERT INTO pm_t_material(MATERIAL_ID,material_no,material_name,requisition_no,line_no,process_type,area,amount,unit,spec,account,org,contact
          ,buyer_code,del_des_code,notes,vendor_no,image_no,objid,objversion,create_type,create_date,update_date) VALUES (
          seq_pm_t_material.nextval,sync_row.material_no,sync_row.material_name,sync_row.requisition_no,sync_row.line_no,coverToProcessType(sync_row.process_type),
          sync_row.area,sync_row.amount,sync_row.unit,sync_row.spec,sync_row.account,sync_row.org,sync_row.contact,coverToBuyerCode(sync_row.buyer_code),sync_row.del_des_code,
          sync_row.notes,sync_row.vendor_no,sync_row.image_no,sync_row.objid,sync_row.objversion,1,to_date(current_version,'yyyy-mm-dd hh:mi:ss'),to_date(current_version,'yyyy-mm-dd hh:mi:ss'));
        
       ELSE
          UPDATE pm_t_material SET material_no= sync_row.material_no,material_name=sync_row.material_name,requisition_no=sync_row.requisition_no,
          line_no=sync_row.line_no,process_type=coverToProcessType(sync_row.process_type),area=sync_row.area,amount=sync_row.amount,unit=sync_row.unit,spec=sync_row.spec,
          account=sync_row.account,org=sync_row.org,contact=sync_row.contact,buyer_code=coverToBuyerCode(sync_row.buyer_code),del_des_code=sync_row.del_des_code,
          notes=sync_row.notes,vendor_no=sync_row.vendor_no,image_no=sync_row.image_no,objversion=sync_row.objversion,update_date=to_date(current_version,'yyyy-mm-dd hh:mi:ss')
          WHERE objid = sync_row.objid;
       END IF;     
     END LOOP;
         INSERT INTO PM_T_SYNC_TIME(SYNCHRONOUS_TIME) VALUES(to_date(current_version,'yyyy-mm-dd hh:mi:ss'));  
     COMMIT;  --提交别忘了,要不然执行完成就自动回滚了
 END synchronous_pm_t_material;

你可能感兴趣的:(DBlink)