运行存储过程时的PLS 00103

时间:2012-08-21 06:10:51

标签: sql plsql

编译时,我收到PLS- 00103 "cur1" when expecting one of the following

之类的错误
CREATE OR REPLACE PACKAGE BODY SSS IS

   PROCEDURE sample1(obj_CustomerID IN varchar2,
                    obj_DelUserID  IN varchar2,
                    cur1           OUT T_CURSOR1,
                    cur2           OUT T_CURSOR2)IS


  BEGIN

   TEMP_CUR1 cur1%ROWTYPE;

   TEMP_CUR2 cur2%ROWTYPE;



    OPEN cur1 FOR
      select distinct cf.fleet_id, cf.fleet_name, cf.customer_id
        from customer_fleet cf, vehicle_register vr, asset_register ar
       where cf.customer_id = vr.customer_id
         and cf.fleet_id = vr.fleet_id
         and vr.vehicle_id = ar.vehicle_id
         and vr.customer_id = ar.customer_id
         and vr.is_active = 'Y'
         and cf.is_active = 'Y';
         FETCH cur1
      into temp_cur1;
    close cur1;

    OPEN CUR2 FOR
      select TEMP_CUR1.fleet_id,
             TEMP_CUR1.fleet_name,
             TEMP_CUR1.customer_id
        from cur1
       where customer_id = obj_CustomerID;

    FETCH CUR2
      INTO TEMP_CUR2;
    CLOSE CUR2;

end Sample1;

END SSS;

错误发生在

   TEMP_CUR1 cur1%ROWTYPE;    
   TEMP_CUR2 cur2%ROWTYPE;

2 个答案:

答案 0 :(得分:1)

变量声明必须在ISBEGIN之间进行,而不是在BEGIN之后:

PROCEDURE sample1(obj_CustomerID IN varchar2, 
                    obj_DelUserID  IN varchar2, 
                    cur1           OUT T_CURSOR1, 
                    cur2           OUT T_CURSOR2)
IS 

   TEMP_CUR1 cur1%ROWTYPE; 
   TEMP_CUR2 cur2%ROWTYPE; 

BEGIN 

答案 1 :(得分:0)

使用Strongly typed REF CURSOR

PROCEDURE sample1(obj_CustomerID IN varchar2, 
                    obj_DelUserID  IN varchar2, 
                    cur1           OUT T_CURSOR1, 
                    cur2           OUT T_CURSOR2)
IS 
   TYPE curr1 IS REF CURSOR RETURN T_CURSOR1%ROWTYPE;
   TYPE curr2 IS REF CURSOR RETURN T_CURSOR2%ROWTYPE;

   TEMP_CUR1 curr1; 
   TEMP_CUR2 curr2; 

BEGIN 

然后

 FETCH cur1
  INTO TEMP_CUR1

FETCH cur2
 INTO TEMP_CUR2