【问题标题】:The code fails because value of JIT_TIME is not found代码失败,因为未找到 JIT_TIME 的值
【发布时间】:2016-08-03 23:15:38
【问题描述】:

下面的函数包含在一个从 shell 脚本调用的 PLSQL 包中。它失败了,因为没有找到 JIT_TIME。我很难弄清楚这个值是从哪里来的。它显然没有作为参数传递,没有存储在任何数据库表中,也没有从任何其他数据库对象中检索。

Function ADD_START_DATE( p_process_type char, p_profet_cntl_no char, p_error_file UTL_FILE.FILE_TYPE) return boolean is                                                                                
        v_profet_control_no     char(10);                                                                                                                                                                        
        v_jit_time              date;                                                                                                                                                                                   
    BEGIN                                                                                                                                                                                                  
        BEGIN                                                                                                                                                                                                 
            SELECT      contr_numb                                                                                                                                                                                   
            INTO        v_profet_control_no                                                                                                                                                                            
            FROM        prd_contr                                                                                                                                                                                      
            WHERE       end_date_time is null                                                                                                                                                                         
            AND         start_date_time is not null                                                                                                                                                                    
            AND         rownum=1;                                                                                                                                                                                      
            PKG_WRITE_ERROR.writeError( p_error_File , 'PRD-01601','ProFET Control No.='||v_profet_control_no);                                                                                                  
            return false;                                                                                                                                                                                        
        EXCEPTION                                                                                                                                                                                             
            when NO_DATA_FOUND then                                                                                                                                                                              
                null;                                                                                                                                                                                               
        END;                                                                                                                                                                                                  
        lock table prd_contr in exclusive mode nowait;                                                                                                                                                        
        BEGIN                                                                                                                                                                                                 
--                                                                                                                                                                                                      
-- A new Begin-End block has been added for jit_time function. If the value                                                                                                                             
-- of jit_time is not found, in case of complete refresh, an error is logged                                                                                                                            
-- and the process exits. In case of routine, jit_time error is ignored.                                                                                                                                
--                                                                                                                                                                                                      
            BEGIN                                                                                                                                                                                                
                v_jit_time:=jit_time;                                                                                                                                                                               
            EXCEPTION                                                                                                                                                                                            
                when OTHERS then                                                                                                                                                                                    
                    IF p_process_type = 'C' then                                                                                                                                                                       
                        PKG_WRITE_ERROR.writeError( p_error_File , 'PRD-01604', '');                                                                                                                                      
                        return false;                                                                                                                                                                                     
                    END IF;                                                                                                                                                                                            
            END;                                                                                                                                                                                                 
            INSERT into prd_contr(start_date_time, end_date_time, idp1_xfer,                                                                                                                                     
                    proc_type, contr_numb, idp1_time)                                                                                                                                                                  
            VALUES(SYSDATE, '','', p_process_type, p_profet_cntl_no,v_jit_time);                                                                                                                                 
        EXCEPTION                                                                                                                                                                                             
            when OTHERS then                                                                                                                                                                                     
                return false;                                                                                                                                                                                       
        END;                                                                                                                                                                                                  
        commit;                                                                                                                                                                                               
        return true;                                                                                                                                                                                          
    EXCEPTION                                                                                                                                                                                              
        when TIMEOUT_ON_RESOURCE then                                                                                                                                                                         
            PKG_WRITE_ERROR.writeError( p_error_File , 'PRD-01602', '');                                                                                                                                         
            return false;                                                                                                                                                                                        
        when OTHERS then                                                                                                                                                                                      
            PKG_WRITE_ERROR.writeError( p_error_File, 'PRD-01699',substr(SQLERRM,1,100));                                                                                                                        
            return false;                                                                                                                                                                                        
    END ADD_START_DATE;   

【问题讨论】:

  • 更新:- JIT_TIME 是与上游的数据库链接
  • JIT_TIME 连接到接受车辆订单的上游系统。

标签: shell unix plsql ksh


【解决方案1】:

我注意到变量 date 是用 v_jit_time 类型定义的,但从未使用过。另一方面,有一个变量 jit_time 从未定义过。 我觉得他们可以合二为一:

Function ADD_START_DATE( p_process_type char, p_profet_cntl_no char, p_error_file UTL_FILE.FILE_TYPE) return boolean is                                                                                
        v_profet_control_no     char(10);                                                                                                                                                                        
        v_jit_time              jit_time;                                                                                                                                                                                   
    BEGIN                                                                                                                                                                                                  
        BEGIN                                                                                                                                                                                                 
            SELECT      contr_numb                                                                                                                                                                                   
            INTO        v_profet_control_no                                                                                                                                                                            
            FROM        prd_contr                                                                                                                                                                                      
            WHERE       end_date_time is null                                                                                                                                                                         
            AND         start_date_time is not null                                                                                                                                                                    
            AND         rownum=1;                                                                                                                                                                                      
            PKG_WRITE_ERROR.writeError( p_error_File , 'PRD-01601','ProFET Control No.='||v_profet_control_no);                                                                                                  
            return false;                                                                                                                                                                                        
        EXCEPTION                                                                                                                                                                                             
            when NO_DATA_FOUND then                                                                                                                                                                              
                null;                                                                                                                                                                                               
        END;                                                                                                                                                                                                  
        lock table prd_contr in exclusive mode nowait;                                                                                                                                                        
        BEGIN                                                                                                                                                                                                 
--                                                                                                                                                                                                      
-- A new Begin-End block has been added for jit_time function. If the value                                                                                                                             
-- of jit_time is not found, in case of complete refresh, an error is logged                                                                                                                            
-- and the process exits. In case of routine, jit_time error is ignored.                                                                                                                                
--                                                                                                                                                                                                      
            BEGIN                                                                                                                                                                                                
                v_jit_time:=jit_time;                                                                                                                                                                               
            EXCEPTION                                                                                                                                                                                            
                when OTHERS then                                                                                                                                                                                    
                    IF p_process_type = 'C' then                                                                                                                                                                       
                        PKG_WRITE_ERROR.writeError( p_error_File , 'PRD-01604', '');                                                                                                                                      
                        return false;                                                                                                                                                                                     
                    END IF;                                                                                                                                                                                            
            END;                                                                                                                                                                                                 
            INSERT into prd_contr(start_date_time, end_date_time, idp1_xfer,                                                                                                                                     
                    proc_type, contr_numb, idp1_time)                                                                                                                                                                  
            VALUES(SYSDATE, '','', p_process_type, p_profet_cntl_no,v_jit_time);                                                                                                                                 
        EXCEPTION                                                                                                                                                                                             
            when OTHERS then                                                                                                                                                                                     
                return false;                                                                                                                                                                                       
        END;                                                                                                                                                                                                  
        commit;                                                                                                                                                                                               
        return true;                                                                                                                                                                                          
    EXCEPTION                                                                                                                                                                                              
        when TIMEOUT_ON_RESOURCE then                                                                                                                                                                         
            PKG_WRITE_ERROR.writeError( p_error_File , 'PRD-01602', '');                                                                                                                                         
            return false;                                                                                                                                                                                        
        when OTHERS then                                                                                                                                                                                      
            PKG_WRITE_ERROR.writeError( p_error_File, 'PRD-01699',substr(SQLERRM,1,100));                                                                                                                        
            return false;                                                                                                                                                                                        
    END ADD_START_DATE;   

【讨论】:

    【解决方案2】:

    据我所知,JIT_TIME 是一个函数。 所以你应该在函数定义中搜索——而不是在参数、变量或表中。

    另外,程序员清楚地预计在某些情况下这个函数不会像在 cmets 中看到的那样被找到

    -- If the value                                                                                                                             
    -- of jit_time is not found, in case of complete refresh, an error is logged                                                                                                                            
    -- and the process exits. In case of routine, jit_time error is ignored.   
    

    【讨论】:

    • 您好,刚刚与DBA团队合作,发现这是一个数据库链接。
    • 这听起来不对。 JIT_TIME 是日期类型,因为 v_jit_time 是日期......所以它可能正在使用数据库链接......但我不认为它本身就是一个数据库链接。
    猜你喜欢
    • 2018-08-30
    • 1970-01-01
    • 2019-02-21
    • 2021-12-15
    • 1970-01-01
    • 2010-11-09
    • 1970-01-01
    相关资源
    最近更新 更多