从java中传过来一个数组,我想从表中查出id不在这个数组中的记录
cursor cur is select from t.name from XXX t where t.id not in temp;
其中temp是一个varchar2,在对数组循环时把数组中的所有id拼接起来赋给temp.然后打开这个cur,fetch,结果not in temp并不起作用。我是这样拼接的:    for i in 1..arr.count
    loop
        temp := temp||''''||arr(i)||''''||',';
    end loop; 
    temp:=substr(temp,1,length(temp)-1);
    temp:= '('||temp||')';
请问我的代码哪里错了,或者大家有什么好的idea ?

解决方案 »

  1.   

    上面cursor写错了cursor cur is select t.name from XXX t where t.id not in temp;
      

  2.   

    这样写也不行 
    v := v|| arr(i) ||',';我刚才试了把数组中的id拼接起来,然后把cursor改成 instr(temp,t.id) = 0 就可以了。
    大家还有什么好的idea 吗?
      

  3.   

    -- 给个例子给你:eygle@SZTYORA> select empno, ename from emp;     EMPNO ENAME
    ---------- --------------------
          7499 ALLEN
          7521 WARD
          7654 MARTIN
          7844 TURNER
          7900 JAMES
          7369 SMITH
          7876 ADAMS已选择7行。eygle@SZTYORA> create or replace procedure emp_proc(v_empnos varchar2, o_cur out sys_refcursor)
      2  is
      3  begin
      4    open o_cur for 'select t.ename from emp t where t.empno in ('||v_empnos||')';
      5  end;
      6  /过程已创建。eygle@SZTYORA>
    eygle@SZTYORA> set serveroutput on;
    eygle@SZTYORA> var c_cur refcursor;
    eygle@SZTYORA> exec emp_proc('7369,7876',:c_cur);PL/SQL 过程已成功完成。eygle@SZTYORA> print c_cur;ENAME
    --------------------
    SMITH
    ADAMS
      

  4.   

    -- 用存储过程,将你的temp变量的内容整理后,当作参数传入存储过程去调用,取其结果!
    -- temp中的内容格式为: 1,2,3,4,...,n 
    -- 具体看我3楼!
      

  5.   

    -- 要not in ,无非就是这样修改一下:
    create or replace procedure emp_proc(v_empnos varchar2, o_cur out sys_refcursor)
    is
    begin
      open o_cur for 'select t.ename from emp t where t.empno not in ('||v_empnos||')';
    end;
    /
      

  6.   

    ('||v_empnos||') 这么写是可以当数字用么?貌似字符串in的时候是找不到的,数字可以