0

任何方式我都可以加快速度。我每次都必须调用存储过程才能从 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;
4

2 回答 2

0

不要在每个过程调用上连接 - 单独的连接代码和您的过程调用代码。


您的过程可能会出现重复的情况(想象一下如果两个会话同时使用相同的键调用它会发生什么 - 如果可能,使用序列而不是最大值。

于 2013-04-20T05:58:21.213 回答
0

您可能可以在 C# 代码中详细说明通过以下查询检索到的结果。

SELECT receiptkey, LPAD (nvl((to_number(MAX(receiptlinenumber))+1),'0'), 5, '0') as NextReceiptLineNumber
FROM receiptdetail
group by receiptkey
于 2013-04-20T11:50:51.027 回答