解决where in list 问题,首要考虑的就是解决列表长度问题和效率问题,效率问题首要考虑绑定变量问题,另外还要考虑比如cardinality对执行计划的影响等
declare
v_condition varchar2(100);
v_sql varchar2(1000);
v_count number(10);
begin
v_condition :='''XY'''||','||'''YZ''';
select count(*)
into v_count
from t
where object_name in(v_condition);
DBMS_OUTPUT.PUT_LINE(v_count);
v_sql:='select count(*) from t where object_name in ('||v_condition||')';
DBMS_OUTPUT.PUT_LINE(v_sql);
end;
/
declare
v_condition varchar2(100);
v_sql varchar2(1000);
v_count number(10);
begin
v_condition :='''XY'''||','||'''YZ''';
v_sql:='select count(*) from t where object_name in ('||v_condition||')';
EXECUTE IMMEDIATE v_sql into v_count;
DBMS_OUTPUT.PUT_LINE(v_count);
DBMS_OUTPUT.PUT_LINE(v_sql);
end;
/