Oracle执行查询速度不理想问题
能给的分不多,但是这个效率不知道在那下手去优化!
string strsql = "select c.id from tb_c c inner join tb_x x ON c.id=x.id where c.id in ({0}) ";
List<string> listQuery=new list<string>();
//假设listQuery 有5条记录
//每条存放1000个id;(如111,222,333,444,555,666)
DataTable dt= new DataTable();
foreach (string strQuery in listQuery)
DataAccess.Query(String.Format(strsql, strQuery), dt2);
foreach (DataRow dr in dt.Rows)
{
//xxxxxxxxxxxxx
}
public static void Query(string strSQL, DataTable dt)
{
OracleConnection conn = new OracleConnection(connectstring);
conn.Open();
OracleDataAdapter adaper = new OracleDataAdapter(strSQL, conn);
adaper.Fill(dt);
conn.Close();
}
[解决办法]
先用循环 生成 所有的查询语句(多条查询语句间加union all返回一个结果集)
然后再一次进行Query方法调用,返回结果集后再进行其他操作
[解决办法]
这是自找麻烦,直接用拆分字符串函数来处理就可以了。
string strsql = @"select c.id from tb_c c inner join tb_x x ON c.id=x.id,
TABLE(getidtable('{0}',',')) B where c.id =B.COLUMN_VALUE";";
CREATE OR REPLACE TYPE table_id IS TABLE OF integer;
create or replace function GetIDTable(p_ID clob,
p_split char) return table_id
pipelined is
v_LEN int; --字符串长度
v_BPOS int; --开始位置
v_EPOS int; --结束位置
v_CPOS int; --当前位置
begin
v_len := DBMS_LOB.getlength(p_ID);
v_BPOS := 1;
v_EPOS := 0;
while v_BPOS <= v_LEN loop
v_CPOS := DBMS_LOB.instr(DBMS_LOB.substr(p_ID, v_LEN, v_BPOS), p_split);
v_EPOS := case v_CPOS when 0 then v_LEN + 1 else v_EPOS + v_CPOS end;
pipe row(to_number(DBMS_LOB.substr(p_ID, v_EPOS - v_BPOS, v_BPOS)));
v_BPOS := v_EPOS + length(p_split);
end loop;
return;
end;