游标中的查询SELECT出错

时间:2012-11-14 11:19:15

标签: select plsql cursor procedure

我的光标选择有问题。选择在其他窗口中正常工作,但我在程序中出现错误,为什么? 我更改了Tabele和数据库的名称,但在此过程之外选择是正常的

我的错误: PL / SQL:ORA-04052: ORA-00604: ORA-03106:

CREATE OR REPLACE PROCEDURE ChangeDismissDate
IS
BEGIN
    DECLARE
          v_id VARCHAR2(40);
          v_dateABC DATE;
          v_dateDismiss DATE;
        CURSOR cur IS
                select emp.EMP_NO, abc.date, emp.DISMISS_DATE  
                from  bazaabc.EmployeesDetails@BAZA_ABC abc,
                      employee_tab emp,
                      person_info_tab pin,
                      oracle_account oa
                where bhd.emp_no = emp.EMP_NO
                and   pin.PERSON_ID = emp.EMP_NO
                and   oa.USERNAME = pin.USER_ID
                and   emp.EMP_NO in (    
                select pi.PERSON_ID from tab_person pi
                where fu.active = 'TRUE'
                and   fu.IDENTITY = pi.USER_ID) AND emp.EMP_NO like '%L%'
                and nvl(abc.date,to_date('20491231','yyyymmdd')) <> nvl(emp.DISMISS_DATE,to_date('20491231','yyyymmdd'));

        BEGIN
                       OPEN cur;
                           LOOP
                                FETCH cur INTO v_id,v_dateABC,v_dateDismiss;

                                 DBMS_OUTPUT.PUT_LINE('v_id:  ' || v_id);
                                 DBMS_OUTPUT.PUT_LINE('v_dateABC:  ' || v_dateABC);
                                 DBMS_OUTPUT.PUT_LINE('v_dateDismiss:  ' ||v_dateDismiss );

                           EXIT WHEN cur%NOTFOUND;
                           END LOOP;
                       CLOSE cur;
        END;

END;
/

1 个答案:

答案 0 :(得分:0)

您可以通过添加例外块

来尝试获得的错误
CREATE OR REPLACE PROCEDURE ChangeDismissDate
IS
BEGIN
    DECLARE
          v_id VARCHAR2(40);
          v_dateABC DATE;
          v_dateDismiss DATE;
        CURSOR cur IS
                select emp.EMP_NO, abc.date, emp.DISMISS_DATE  
                from  bazaabc.EmployeesDetails@BAZA_ABC abc,
                      employee_tab emp,
                      person_info_tab pin,
                      oracle_account oa
                where bhd.emp_no = emp.EMP_NO
                and   pin.PERSON_ID = emp.EMP_NO
                and   oa.USERNAME = pin.USER_ID
                and   emp.EMP_NO in (    
                select pi.PERSON_ID from tab_person pi
                where fu.active = 'TRUE'
                and   fu.IDENTITY = pi.USER_ID) 
                AND emp.EMP_NO like '%L%'
                and nvl(abc.date,to_date('20491231','yyyymmdd')) <>  
                nvl(emp.DISMISS_DATE,to_date('20491231','yyyymmdd'));

        BEGIN
                       OPEN cur;
                           LOOP
                  FETCH cur INTO v_id,v_dateABC,v_dateDismiss;    
                  DBMS_OUTPUT.PUT_LINE('v_id:  ' || v_id);
                  DBMS_OUTPUT.PUT_LINE('v_dateABC:  ' || v_dateABC);
                  DBMS_OUTPUT.PUT_LINE('v_dateDismiss:  ' ||v_dateDismiss );

                           EXIT WHEN cur%NOTFOUND;
                           END LOOP;
                       CLOSE cur;
        END;
EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
        DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_stack);
    WHEN OTHERS
    THEN
        DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_stack);

END;
/