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'' –