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
    魔兽就是毒瘤,大家千万不要玩。
  • 相关阅读:
    maven 多环境打包
    velocity 将数字转为以万为单位,保留2位小数
    mybatic 结果为null,返回0
    websocket-spring 整合
    烂泥:rsync配置文件详解
    烂泥:【转】rsync命令参数详解
    烂泥:linux文件同步之rsync学习(一)
    烂泥:使用snmpwalk采集设备的OID信息
    烂泥:apache密码生成工具htpasswd的应用
    烂泥:apache性能测试工具ab的应用
  • 原文地址:https://www.cnblogs.com/tracy/p/1793347.html
Copyright © 2011-2022 走看看