[英]Oracle insert lots of data to temporary table
我需要在临时表中插入12000个字符串,每个字符串6个字符。 目前,我正在使用SELECT Code FROM Articles where Code = '111111' OR Code = '222222' ...
来执行此操作,该命令具有40万个字符,执行时间为20秒。 我想知道如何加快这个过程?
我不需要验证我的代码。 它们需要作为查询的一部分或作为命令参数从应用程序传输到数据库。
我真的不需要Select Code From Articles
,但是oracle不支持INSERT INTO (...) VALUES (...)
多个记录INSERT INTO (...) VALUES (...)
IN
通常比OR
快,因为一旦满足条件, IN
就会停止评估。 在这里查看上一个q
所以:
Select code
from Articles
where Code in ('111111','222222')
为了允许非常大的列表,元组:
Select code
from Articles
where ('1', Code) in (('1','111111'),
('1','222222')...)
正如@AlexPoole指出的那样,最好使用表值参数。
type t_varchar_tab is table of varchar2(10) index by pls_integer;
procedure insert_table(i_id_tab in t_varchar_tab);
身体:
procedure insert_table(i_id_tab in t_varchar_tab) is
begin
-- if You have temporary table You do not want commits here
forall i in i_id_tab.first .. i_id_tab.last
insert into MY_SCHEMA.MY_TABLE
VALUES (i_id_tab(i));
end ins_test;
C#:
using (OracleCommand dbCommand = connection.CreateCommand())
{
dbCommand.CommandText = "MY_SCHEMA.MY_PACKAGE.insert_table";
dbCommand.CommandType = CommandType.StoredProcedure;
var inputArray = new OracleParameter
{
Direction = ParameterDirection.Input,
CollectionType = OracleCollectionType.PLSQLAssociativeArray,
Value = StringList.ToArray()
};
dbCommand.Parameters.Add(inputArray);
await dbCommand.ExecuteNonQueryAsync();
谢谢亚历克斯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.