从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 ?
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 ?
v := v|| arr(i) ||',';我刚才试了把数组中的id拼接起来,然后把cursor改成 instr(temp,t.id) = 0 就可以了。
大家还有什么好的idea 吗?
---------- --------------------
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
-- temp中的内容格式为: 1,2,3,4,...,n
-- 具体看我3楼!
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;
/