你的exit when 应紧跟在fetch之后

解决方案 »

  1.   

    逻辑问题,先判断有没有取出数据,再进行相关操作
    create or replace procedure aaaa is
      type sp_test1_cursor is ref cursor;
      test1_cursor sp_test1_cursor;
      v_name       t_gxp_apply_main%rowtype;
    begin
      open test1_cursor for
        select * from t_gxp_apply_main where cbillcode in ('OPACG20144000100');--只能查询出一条数据
      loop
        fetch test1_cursor
          into v_name;
        exit when test1_cursor%notfound;
        if v_name.cbillcode is not null or v_name.cbillcode='' then
          dbms_output.put_line(v_name.cpurchaseuse);
        end if;
      end loop;
      close test1_cursor;
    end aaaa;
      

  2.   

    这句要前提
        exit when test1_cursor%notfound;
      

  3.   

    exit when应紧跟在loop 中的 fetch into 之后
      

  4.   

    你的exit when放在输出语句的后面了,所以会输出两条
      

  5.   

    推荐用其他的控制结构,先判断后操作,比较符合正常思维,比如:FOR 比较好理解