下面的程序(当我取消注释评论的部分时)显示'没有找到数据'..?

时间:2015-11-05 05:26:49

标签: oracle plsql oracle11g

您好我正在尝试以下逻辑代码..我需要帮助.. 当我运行以下程序时,我得到所有sid以及特定月份的相应pid。但当我取消注释我在这里评论过的部分时,我会显示月份和年份,然后显示“未找到数据”的消息。我哪里错了?

 create or replace PROCEDURE mas(V_MONTH NUMBER DEFAULT NULL,V_YEAR NUMBER DEFAULT NULL,V_AID VARCHAR2) AS

V_MID VARCHAR2(50);
V_SID VARCHAR2(50);
v_v_month number := nvl(V_MONTH,to_number(to_char(sysdate,'mm')));
v_v_year number := nvl(V_YEAR,to_number(to_char(sysdate,'yyyy')));
v_is_sub PM.IS_SUB%TYPE;
V_DIST_s NUMBER;
V_DIST_t NUMBER;


 cursor c1 
  is
    select distinct a.mid,
                      b.sid
    from     pmt a
             inner join smt b  
             on (a.mid = b.mid)
    where    a.AID = V_AID      
    AND A.AID = B.AID 
    AND EXTRACT(MONTH FROM A.RDATE)= v_v_month AND 
    EXTRACT(YEAR FROM A.RDATE)= v_v_year
    order by mid;

BEGIN


dbms_output.put_line('month : ' || v_v_month);
dbms_output.put_line('year : ' || v_v_year);

/*
select IS_SUB into v_is_sub from program_master where pid = 'V_AID';

IF v_is_sub = 1 then

  select count(*) into V_DIST_S from (select distinct sid from smt where aid = 'v_aid');

  select count(*) into V_DIST_T from (select distinct sid from tm where aid = 'v_aid');

   if(V_DIST_S = V_DIST_T) then

*/
    for rec1 in c1

    loop

      dbms_output.put_line('MID : ' || rec1.MID);
      dbms_output.put_line('SID : ' || rec1.SID);

    end loop;

--  else

  --  dbms_output.put_line('count of sids do not match');

--end if;

--else

--dbms_output.put_line('No sids available for the mentioned pid.');


--end if;

END MAS;

1 个答案:

答案 0 :(得分:1)

where pid = 'V_AID';

V_AID变量,但是,您已将其括在单引号中,这使其成为字符串 。因此,您实际上在寻找值'V_AID'而不是变量的值。

将其修改为:

select IS_SUB into v_is_sub from program_master where pid = V_AID;

在将变量括在单引号中的任何地方都这样做。