測試環境: Oracle 10g java
1.原理 sql
select * from table(split('a,b,c'))結果:
a b c2.結論
對於相似: 函數
select * from xxx_table where xxx_column in ('xxa', 'xxb', 'xxc')可動態傳入in子句參數
select * from xxx_table where xxx_column in (select * from table(split(?)))
PreparedStatement stmt = conn.prepareStatement(sql); stmt.setObject(1, "xxa,xxb,xxc");
附split函數: oop
create or replace type split_tbl as table of varchar(32767); / create or replace function split ( p_list varchar2, p_del varchar2 := ',' ) return split_tbl pipelined is l_idx pls_integer; l_list varchar2(32767) := p_list; l_value varchar2(32767); begin loop l_idx := instr(l_list,p_del); if l_idx > 0 then pipe row(substr(l_list,1,l_idx-1)); l_list := substr(l_list,l_idx+length(p_del)); else pipe row(l_list); exit; end if; end loop; return; end split; /
原文:http://stackoverflow.com/questions/178479/preparedstatement-in-clause-alternatives 測試