怎么在oracle的查询语句中的in后用变量

2025-03-23 00:13:59
推荐回答(2个)
回答1:

要想在in中用变量,需要用动态SQL,请看下例子,我在oracle 10g中测试通过:

declare
v_1 varchar2(100);
v_2 varchar2(200);
begin
v_1:='(''1'',''2'',''3'')';
v_2:='insert into testa2 select * from testa1 where fch in'|| v_1;
execute immediate v_2;
commit;
end;

回答2:

delete from table1 t where t.field1 in
(select t.field1 from table1 t, table2 t1
where .......)