zoukankan      html  css  js  c++  java
  • ODP.NET Tip: Bind Variables and the BindByName Property

    When using bind variables in the CommandText property of an OracleCommand object, it is important to understand the meaning of the value of the BindByName property for the OracleCommand object. This property is a read/write boolean property which defaults to false. The fact that this property defaults to false means that ODP.NET operates, by default, in what is known as "bind by position" mode. In this mode, when OracleParameter objects are added to the parameters collection for an OracleCommand object, they must be added to the collection in the same order in which they appear in the CommandText property.

    For example, say you have the following:

    // assumes cmd is an object of type OracleCommand
    cmd.CommandText = "select employee_id from hr.employees where first_name = :1 and last_name = :2"

    In this sample, there are 2 bind variables used (denoted by :1 and :2 in the text). Using the default setting (false) for the BindByName property this means that the OracleParameter object for the first_name placeholder should be added to the parameters collection first followed by the OracleParameter object for the last_name placeholder.

    In contrast to this, if you set the BindByName property to true, you may add the OracleParameter objects to the parameters collection in any order you wish. Of course, if you set the property to true, you also need to ensure that the ParameterName property of the OracleParameter object matches the name used in the CommandText (without the ":").

    Another area where the value of the BindByName property may be the source of confusion is when using a PL/SQL function. For example, say you have a function that returns a value and accepts 2 parameters as input. When you use this function in your code, the following pseudo-code represents what is sent to the database:

    :return_value := some_function (:parameter1, :parameter2)

    Notice that the return value is the first bind variable used. Therefore, in bind by position mode (the default!), you must add the OracleParameter object for the return value to the parameters collection first (not last!), followed by the parameter object for "parameter1" and then "parameter2".

    http://www.oracle.com/technology/tech/windows/odpnet/newfeatures.html
    魔兽就是毒瘤,大家千万不要玩。
  • 相关阅读:
    剑指Offer-49.把字符串转换成整数(C++/Java)
    codeforces Gym 100338H High Speed Trains (递推,高精度)
    codeforces Gym 100338E Numbers (贪心,实现)
    codeforces Gym 100338C Important Roads (重建最短路图)
    HDU 4347 The Closest M Points (kdTree)
    UVA 10817
    HDU 4348 I
    HDU 4341 Gold miner (分组背包)
    UVA 1218
    UVA 1220 Party at Hali-Bula (树形DP)
  • 原文地址:https://www.cnblogs.com/tracy/p/1793347.html
Copyright © 2011-2022 走看看