1.SQL> create or replace type vartabletype as table of varchar2(1000);
2 /
Type created.
2.SQL> create or replace function str2varList( p_string in varchar2 ) return VarTableType
2 as
3 v_str long default p_string || ',';
4 v_n varchar2(2000);
5 v_data VarTableType := VarTableType();
6 begin
7 loop
8 v_n :=instr( v_str, ',' );
9 exit when (nvl(v_n,0) = 0);
10 v_data.extend;
11 v_data( v_data.count ) := ltrim(rtrim(substr(v_str,1,v_n-1)));
12 v_str := substr( v_str, v_n+1 );
13 end loop;
14 return v_data;
15 end;
16 /
Function created.
执行上面的函数后,用变量S进行测试:
SQL> var s varchar2(100)
SQL> exec :s:='a,b,c';
PL/SQL procedure successfully completed.
SQL> print s
S
--------------------------------------------------------------------------------
a,b,c
SQL> select * from table(str2varList(:s)) a;
COLUMN_VALUE
--------------------------------------------------------------------------------
a
b
c
使用绑定变量的时候可以用IN (select * from table(str2varList(:s)) a;)
现在要做一些修改
1.在 ARTICLECONTENT 的ARTICLEID 和
ANALYZE TABLE ARTICLECONTENT COMPUTE STATISTICS FOR ALL INDEXED COLUMNS;
create or replace function str2varList( p_string in varchar2 ) return VarTableType
2 as
3 v_str long default p_string || ',';
4 v_n varchar2(2000);
5 v_data VarTableType := VarTableType();
6 begin
7 loop
8 v_n :=instr( v_str, ',' );
9 exit when (nvl(v_n,0) = 0);
10 v_data.extend;
11 v_data( v_data.count ) := ltrim(rtrim(substr(v_str,1,v_n-1)));
12 v_str := substr( v_str, v_n+1 );
13 end loop;
14 return v_data;
15 end;
在程序中使用方法:
select v.articleid, v.zsturl, v.content, v.groupid, v.arr_gcid, v.path from v_csteel_news v where v.path in(select * from table(str2varList('xyzx,fdc,jx,sh,zc,dl,jd,dj,jcjs,xysj,xyzx,gjbz,jj,byq,qc,xyzs') )a) and v.rootgroupid =395 and rownum<=5
根据实际测试,速度是提高不少!