表T中数据如下:
A   B 
1   a
2   b
7   e
存储过程如下:
create or replace procedure test is
cursor v_cur_6(ids varchar2) is
       select * from T where to_char(A) not in (ids);
v_cur_line_6 v_cur_6%ROWTYPE;
begin
     open v_cur_6('1,2');
    loop       fetch v_cur_6 into v_cur_line_6;
       exit when v_cur_6%notfound;
       dbms_output.put_line('---------');
    end loop;
    close v_cur_6;
end;
希望的结果,通过游标参数ids过滤掉部分数据,可是我发现这样写所有数据都会出来,为什么呢,应该1、2行的数据被过滤掉啊,帮我看看原因,谢谢各位

解决方案 »

  1.   

    条件不对:
    你直接用select语句把它过滤掉就好了,为何还用游标才过滤呢?create or replace procedure test is 
    cursor v_cur_6(ids varchar2) is 
          select * from T where A not in (1,2); 
    ........
    .........
      

  2.   

    改为这样,试试:
    create or replace procedure test is 
    cursor v_cur_6(ids varchar2) is 
          select * from T where instr(ids,to_char(A))=0; 
    v_cur_line_6 v_cur_6%ROWTYPE; 
    begin 
        open v_cur_6('1,2'); 
        loop       fetch v_cur_6 into v_cur_line_6; 
          exit when v_cur_6%notfound; 
          dbms_output.put_line('---------'); 
        end loop; 
        close v_cur_6; 
    end; 
      

  3.   

    再改一点,这样更保证一些:
    create or replace procedure test is 
    cursor v_cur_6(ids varchar2) is 
          select * from T where instr(','||ids||',',','||to_char(A)||',')=0; 
    v_cur_line_6 v_cur_6%ROWTYPE; 
    begin 
        open v_cur_6('1,2'); 
        loop       fetch v_cur_6 into v_cur_line_6; 
          exit when v_cur_6%notfound; 
          dbms_output.put_line('---------'); 
        end loop; 
        close v_cur_6; 
    end; 
      

  4.   

    select * from T where instr(ids,to_char(A))=0; 这样应该可以的
      

  5.   

    参数传错了,按你传的是表示查找A不等于'1,2'的数据,所以三条数据都会出来
    实际上你的要求不是这样
    也就是说
    这个过程实际执行的是下面的SQL
    select * from T where to_char(A) not in ('1,2'); 
    而你想要的SQL是
    select * from T where to_char(A) not in ('1','2');