procedure proc_GetAgentDaily(p_cursor out sys_refcursor)as
 Operator_Id number;
 Agent varchar2(50);
 ext_code varchar2(100);
 HBill NUMBER;
 JBill NUMBER;
 PBill NUMBER;
 AllBill NUMBER;
 name varchar2(500);
 state NUMBER;
 ID NUMBER;
  Cursor Cur is Select ID,agent_name,ext_code from tbl_agent  where length(ext_code)>=3;
 begin
   delete from tbl_Storage;
   delete from tbl_stor_linshi;
  insert into tbl_stor_linshi(AGENT_ID,NO) select   AGENT_ID , NO  from tbl_event where to_char(DEAL_DATE,'yyyy')=to_char(sysdate,'yyyy') and to_char(DEAL_DATE,'MM')=to_char(sysdate,'MM') and to_char(DEAL_DATE,'DD')=to_char(sysdate,'DD');
  commit;
   Open Cur;
   Fetch  Cur Into ID,Agent,ext_code;
   While Cur%found  loop
     select count(NO) into HBill from tbl_stor_linshi where  AGENT_ID = ID and NO in (select EVENT_NO FROM tbl_event_detail WHERE DEAL_CATEGORY = 421);
     select count(NO) into PBill from tbl_stor_linshi where AGENT_ID = ID and NO in (select EVENT_NO FROM tbl_event_detail WHERE DEAL_CATEGORY = 422  OR DEAL_CATEGORY = 4);
     select count(NO) into JBill from tbl_stor_linshi where AGENT_ID = ID and NO in (select EVENT_NO FROM tbl_event_detail WHERE DEAL_CATEGORY = 3);
     select count(NO) into AllBill from tbl_stor_linshi where AGENT_ID = ID ;
     select case when category is null then 1 else category end into state from tbl_agent_operate where rownum<2 and tbl_agent_operate.agent_id=ID order by tbl_agent_operate.ID desc;
    insert into tbl_Storage(Operator_Id,Agent,ext_code,HBill,JBill,PBill,AllBill)values(ID,Agent,ext_code,HBill,JBill,PBill,AllBill);
    commit;
   Fetch  Cur Into ID,Agent,ext_code;
    end loop;
 Close Cur;
 open p_cursor for  select * from tbl_Storage;
 end proc_GetAgentDaily;红色标记处,老是提示未找到数据 ora-01403但是Select ID,agent_name,ext_code from tbl_agent  where length(ext_code)>=3;  中id的值在tbl_agent_operate 中都能找到记录,

解决方案 »

  1.   

    你的是这句话提示找不到数据,
    select case when category is null then 1 else category end into state from tbl_agent_operate where rownum<2 and tbl_agent_operate.agent_id=ID order by tbl_agent_operate.ID desc;
    那你查的到不啊? 去掉into 查下呢
    我怀疑是rownum<2 放在最前面了的问题
      

  2.   

    select category into state
    from (select nvl(category,1) as category 
          from   tbl_agent_operate 
          where  tbl_agent_operate.agent_id=ID 
          order  by tbl_agent_operate.ID desc ) t
    where rownum<2;
      

  3.   

    gelyon  rownum<2放在后面也不行, 去掉into 编译时直接提示 "在此select 语句中缺少into 子句" 费解关于 子查询 倒是很好,但是还是提示 未找到数据, 如果在select max(category) into state加max,执行时倒是不提示错误,但是值全部问null, 希望大哥帮忙看看fetch cur 没错误吧
      

  4.   

    procedure proc_GetAgentDaily(p_cursor out sys_refcursor)as
     Operator_Id number;
     Agent varchar2(50);
     ext_code varchar2(100);
     HBill NUMBER;
     JBill NUMBER;
     PBill NUMBER;
     AllBill NUMBER;
     name varchar2(500);
     state NUMBER;
     ID NUMBER;你试试把你的变量名称改为ID_N