任何方式我都可以加快速度。我每次都必须调用存储过程才能从 oracle 获取其最新值并进行更新。这是我的最后一个瓶颈,因为它可以被调用数千次。我将其他插入转换为数组绑定批量插入。
c#调用oracle
for (int i = 0; i < r.receiptkey.Count(); i++)
{
ld.receiptlinenumber.Add(AsnGetNextAvailableReceiptLineNumber(r.receiptkey[i]));
}
时间:2019-04-10 标签:c#oracle
public string AsnGetNextAvailableReceiptLineNumber(string myReceiptKey)
{
using (OracleCommand cmd = new OracleCommand())
{
OracleConnection conn;
conn = new OracleConnection(ConnectionStringOracle);
cmd.CommandText = "bpPack.GetNextReceiptLineNumber";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.Parameters.Add(new OracleParameter("iReceiptKey", OracleDbType.Varchar2, 10));
cmd.Parameters.Add(new OracleParameter("oRetValue", OracleDbType.Varchar2, 5)).Direction = ParameterDirection.Output;
cmd.Parameters["iReceiptKey"].Value = myReceiptKey;
conn.Open();
try
{
cmd.ExecuteNonQuery();
}
catch (Exception e9)
{
return "Error" + e9.Message;
}
return cmd.Parameters["oRetValue"].Value.ToString();
}
}
plsql
PROCEDURE GetNextReceiptLineNumber(
iReceiptKey IN VARCHAR2,
oRetValue OUT VARCHAR2)
IS
xreceiptlinenumber VARCHAR2 (5);
xreceiptlinecount NUMBER (10);
BEGIN
xreceiptlinenumber :='';
xreceiptlinecount := 0;
SELECT MAX (receiptlinenumber)
INTO xreceiptlinenumber
FROM receiptdetail
WHERE receiptkey = iReceiptKey;
IF (xreceiptlinenumber IS NULL) THEN
xreceiptlinecount := 0;
ELSE
xreceiptlinecount := TO_NUMBER (LTRIM (xreceiptlinenumber, '0'));
END IF;
xreceiptlinecount := xreceiptlinecount + 1;
oRetValue := LPAD (xreceiptlinecount, 5, '0');
END GetNextReceiptLineNumber;