users
表中没有行,其中user_id
的值为'101,102,103'。
如果要将字符串拆分为一组单独的值,则必须做的不仅仅是在not in
表达式中使用它。
一些可能的方案:
declare
p_csvlist varchar2(100) := '2002, 7369, 7499, 7902, 7934';
v_count integer;
begin
select count(*) into v_count
from emp e
where e.empno in
(select extractvalue(xt.column_value,'e')
from table(xmlsequence
(extract
(xmltype('<coll><e>' || replace(p_csvlist,',','</e><e>') || '</e></coll>')
, '/coll/*'))) xt);
dbms_output.put_line(v_count || ' rows');
end;
或本
declare
p_csvlist varchar2(100) := '2002, 7369, 7499, 7902, 7934';
v_count integer;
begin
select count(*) into v_count
from emp e
where e.empno in
(select regexp_substr(p_csvlist, '[^,]+',1,rownum)
from dual
connect by rownum <= length(p_csvlist) - length(replace(p_csvlist,',')));
dbms_output.put_line(v_count || ' rows');
end;
或本(只适用于数值):
declare
p_csvlist varchar2(100) := '2002, 7369, 7499, 7902, 7934';
v_count integer;
begin
select count(*) into v_count
from emp e
where e.empno in
(select to_number(xt.column_value)
from xmltable(p_csvlist) xt);
dbms_output.put_line(v_count || ' rows');
end;
的例子是从我的FAQ文章: www.williamrobertson.net/documents/comma-separated.html
'在条款没有按规定sys.DBMS_DEBUG_VC2COLL --collection数据类型” t正常工作“,它可以正常工作。您没有向'in'条款传递值列表,您只传递一个值-''101,102,103'' –