--归档同步存储过程,用ORACLE JOB去进行调用
create or replace procedure pro_synXcProcActive is
  KEY_ID   INTEGER;
  ERR_CODE NUMBER;
  ERR_MSG  VARCHAR2(512);  strDeclNo           varchar2(20);
  strNextFlowNode     VARCHAR2(10);
  strInspOperatorCode VARCHAR2(6);
  
  cursor getProcActive is
    select v.decl_no, v.next_flow_node, v.insp_operator_code
      from t_bill_list a, v_proc_active v
     where 1 = 1
       and a.decl_no = v.decl_no
       and a.process_status <> v.next_flow_node;
begin
  open getProcActive;
  fetch getProcActive
    into strDeclNo, strNextFlowNode, strInspOperatorCode;
  while getProcActive% found loop
    update t_bill_list t
       set t.process_status = strNextFlowNode,
           t.operator_code  = strInspOperatorCode
     where t.decl_no = strDeclNo;
  end loop; 
  --dbms_output.put_line(to_char(getProcActive%rowcount));  
  Close getProcActive;
  commit;
    EXCEPTION
    when others then SELECT T_ORACLE_ERROR_SEQ.NEXTVAL INTO KEY_ID FROM DUAL; 
    ERR_MSG := SQLERRM; 
    ERR_CODE := SQLCODE; 
    INSERT INTO T_ORACLE_ERROR(ERROR_ID, ERR_MSG, DECL_NO, ERR_CODE, MEMO, ERR_DATE) 
    VALUES(KEY_ID, ERR_MSG, '', ERR_CODE, '单据状态同步存储过程错误', sysdate);
    rollback;
end pro_synXcProcActive;执行这个存储过程,但是执行不到update,有时exec 存储过程时还死住不动,请高手赐教,急

解决方案 »

  1.   

    update t_bill_list t
           set t.process_status = strNextFlowNode,
               t.operator_code  = strInspOperatorCode
         where t.decl_no = strDeclNo;
      end loop; 
      --dbms_output.put_line(to_char(getProcActive%rowcount));  
      Close getProcActive;
      commit;改成:    update t_bill_list t
           set t.process_status = strNextFlowNode,
               t.operator_code  = strInspOperatorCode
         where t.decl_no = strDeclNo;
         commit;
      end loop; 
      --dbms_output.put_line(to_char(getProcActive%rowcount));  
      Close getProcActive;
      试试
      

  2.   

    去掉游标,改成:for xx in (
      select v.decl_no, v.next_flow_node, v.insp_operator_code
          from t_bill_list a, v_proc_active v
         where 1 = 1
           and a.decl_no = v.decl_no
           and a.process_status <> v.next_flow_node
    ) loop...end loop;
      

  3.   

    open getProcActive;
      fetch getProcActive
        into strDeclNo, strNextFlowNode, strInspOperatorCode;
      while getProcActive% found loop
        update t_bill_list t
           set t.process_status = strNextFlowNode,
               t.operator_code  = strInspOperatorCode
         where t.decl_no = strDeclNo;
      end loop; 
    ---
    循环里没有
      fetch getProcActive
        into strDeclNo, strNextFlowNode, strInspOperatorCode;
    是个死循环!
      

  4.   

    同意楼上和楼上的楼上说的
    另外,如一楼所说,最好在loop里面提交,也就是改成open getProcActive;
      while getProcActive% found loop
        fetch getProcActive
        into strDeclNo, strNextFlowNode, strInspOperatorCode;
        update t_bill_list t
           set t.process_status = strNextFlowNode,
               t.operator_code  = strInspOperatorCode
         where t.decl_no = strDeclNo;
        commit;
      end loop;
      

  5.   

    楼主哪里看来得cursor循环表达?是自编的还是看错了?oracle语法挺苛刻的,像我们这样的初学者还是先按书里的表达练习,节省很多时间的。
      

  6.   

    将  
    open getProcActive;
      fetch getProcActive
        into strDeclNo, strNextFlowNode, strInspOperatorCode;
      while getProcActive% found loop
        update t_bill_list t
           set t.process_status = strNextFlowNode,
               t.operator_code  = strInspOperatorCode
         where t.decl_no = strDeclNo;
      end loop; 
      --dbms_output.put_line(to_char(getProcActive%rowcount));  
      Close getProcActive;
      commit;改为
      open getProcActive;
      loop
      fetch getProcActive
        into strDeclNo, strNextFlowNode, strInspOperatorCode;
      EXIT WHEN getProcActive%NOTFOUND;
        update t_bill_list t
           set t.process_status = strNextFlowNode,
               t.operator_code  = strInspOperatorCode
         where t.decl_no = strDeclNo;
      end loop; 
      --dbms_output.put_line(to_char(getProcActive%rowcount));  
       commit;
      Close getProcActive;