OracleParameter 类

定义

表示 OracleCommand 的参数,还可以表示它到 DataColumn 的映射。Represents a parameter to an OracleCommand and optionally its mapping to a DataColumn. 此类不能被继承。This class cannot be inherited.

public ref class OracleParameter sealed : System::Data::Common::DbParameter, ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Data.OracleClient.OracleParameter/OracleParameterConverter))]
public sealed class OracleParameter : System.Data.Common.DbParameter, ICloneable
type OracleParameter = class
    inherit DbParameter
    interface ICloneable
    interface IDbDataParameter
    interface IDataParameter
Public NotInheritable Class OracleParameter
Inherits DbParameter
Implements ICloneable
继承
OracleParameter
属性
实现

示例

下面的示例通过 OracleDataAdapter中的 OracleParameterCollection 创建多个 OracleParameter 实例。The following example creates multiple instances of OracleParameter through the OracleParameterCollection within the OracleDataAdapter. 这些参数用于从数据库中选择数据,并将数据放入 DataSet中。These parameters are used to select data from the database and place the data in the DataSet. 此示例假设已使用适当的架构、命令和连接创建了 DataSetOracleDataAdapterThis example assumes that a DataSet and an OracleDataAdapter have already been created by using the appropriate schema, commands, and connection.

public void AddOracleParameters() 
 {
 // ...
 // create dataSet and adapter
 // ...
   adapter.SelectCommand.Parameters.Add("pEName", OracleType.VarChar, 80).Value = "Smith";
   adapter.SelectCommand.Parameters.Add("pEmpNo", OracleType.Int32).Value = 7369;
   adapter.Fill(dataSet);
 }

Public Sub AddOracleParameters()
    ' ...
    ' create dataSet and adapter
    ' ...
adapter.SelectCommand.Parameters.Add("pEName", OracleType.VarChar, 80).Value = "Smith"
adapter.SelectCommand.Parameters.Add("pEmpNo", OracleType.Int32).Value = 7369
adapter.Fill(dataSet)
End Sub 

注解

参数名称不区分大小写。Parameter names are not case-sensitive.

使用 Oracle 的 Microsoft OLE DB 提供程序(MSDAORA)和 ODBC.NET Framework 数据提供程序查询 Oracle 数据库时,如果使用 LIKE 子句来查询固定长度字段中的值,则可能不会返回所有预期匹配项。When querying an Oracle database using the Microsoft OLE DB Provider for Oracle (MSDAORA) and the ODBC.NET Framework Data Provider, using the LIKE clause to query values in fixed-length fields may not return all expected matches. 原因在于,当 Oracle 在 LIKE 子句中匹配固定长度字段的值时,它将与字符串的整个长度匹配,其中包括任何空白尾随空格。The reason is that when Oracle matches values for fixed-length fields in a LIKE clause, it matches the entire length of the string, including any padding trailing spaces. 例如,如果 Oracle 数据库中的某个表包含一个名为 "Field1" 的字段,该字段定义为 char(3),并且您在该表的行中输入值 "a",则以下代码将不会返回该行。For example, if a table in an Oracle database contains a field named "Field1" that is defined as char(3), and you enter the value "a" into a row of that table, the following code will not return the row.

Dim queryString As String = "SELECT * FROM Table1 WHERE Field1 LIKE ?"  
Dim command As OleDbCommand = New OleDbCommand(queryString, connection)  
command.Parameters.Add("@p1", OleDbType.Char, 3).Value = "a"  
Dim reader As OleDbDataReader = command.ExecuteReader()  
string queryString = "SELECT * FROM Table1 WHERE Field1 LIKE ?";  
OleDbCommand command = new OleDbCommand(queryString, connection);  
command.Parameters.Add("@p1", OleDbType.Char, 3).Value = "a";  
OleDbDataReader reader = command.ExecuteReader();  

这是因为 Oracle 将列值存储为 "a" (填充 "a",尾随空格,固定字段长度为3),在 LIKE 固定长度字段比较的情况下,Oracle 不会将其视为 "a" 参数值的匹配项。This is because Oracle stores the column value as "a " (padding "a", with trailing spaces, to the fixed field length of 3), which Oracle does not treat as a match for the parameter value of "a" in the case of a LIKE comparison of fixed-length fields.

若要解决此问题,请向参数值("a%")追加一个百分比(%)通配符,或者改为使用 SQL = 比较。To resolve this problem, append a percentage ("%") wildcard character to the parameter value ("a%"), or use an SQL = comparison instead.

构造函数

OracleParameter()

初始化 OracleParameter 类的新实例。Initializes a new instance of the OracleParameter class.

OracleParameter(String, Object)

初始化使用参数名称和 OracleParameter 对象的 OracleParameter 类的新实例。Initializes a new instance of the OracleParameter class that uses the parameter name and an OracleParameter object.

OracleParameter(String, OracleType)

初始化使用参数名称和数据类型的 OracleParameter 类的新实例。Initializes a new instance of the OracleParameter class that uses the parameter name and data type.

OracleParameter(String, OracleType, Int32)

初始化使用参数名称、数据类型和长度的 OracleParameter 类的新实例。Initializes a new instance of the OracleParameter class that uses the parameter name, data type, and length.

OracleParameter(String, OracleType, Int32, ParameterDirection, Boolean, Byte, Byte, String, DataRowVersion, Object)

初始化 OracleParameter 类的新实例,该类使用参数名称、数据类型、长度、源列名、参数方向、数值精度和其他属性。Initializes a new instance of the OracleParameter class that uses the parameter name, data type, length, source column name, parameter direction, numeric precision, and other properties.

OracleParameter(String, OracleType, Int32, ParameterDirection, String, DataRowVersion, Boolean, Object)

初始化使用参数名称、数据类型、大小、方向、源列、源版本和其他属性的 OracleParameter 类的一个新实例。Initializes a new instance of the OracleParameter class that uses the parameter name, data type, size, direction, source column, source version, and other properties.

OracleParameter(String, OracleType, Int32, String)

初始化使用参数名称、数据类型、长度和源列名称的 OracleParameter 类的新实例。Initializes a new instance of the OracleParameter class that uses the parameter name, data type, length, and source column name.

属性

DbType

获取或设置参数的 DbTypeGets or sets the DbType of the parameter.

Direction

获取或设置一个值,该值指示参数是只可输入的参数、只可输出的参数、双向参数还是存储过程返回值参数。Gets or sets a value that indicates whether the parameter is input-only, output-only, bidirectional, or a stored procedure return value parameter.

IsNullable

获取或设置一个值,该值指示参数是否接受 null 值。Gets or sets a value that indicates whether the parameter accepts null values.

Offset

获取或设置 Value 属性的偏移量。Gets or sets the offset to the Value property.

OracleType

获取或设置参数的 OracleTypeGets or sets the OracleType of the parameter.

ParameterName

获取或设置 OracleParameter 的名称。Gets or sets the name of the OracleParameter.

Precision

获取或设置用于表示 Value 属性的最大位数。Gets or sets the maximum number of digits used to represent the Value property.

Scale

获取或设置所解析的 Value 的小数位数。Gets or sets the number of decimal places to which Value is resolved.

Size

获取或设置列中的数据的最大大小(以字节为单位)。Gets or sets the maximum size, in bytes, of the data within the column.

SourceColumn

获取或设置映射到 DataSet 并且用于加载或返回 Value 的源列的名称Gets or sets the name of the source column mapped to the DataSet and used for loading or returning the Value

SourceColumnNullMapping

获取或设置一个值,该值指示源列是否可以为 null。Gets or sets a value which indicates whether the source column is nullable. 通过此操作,OracleCommandBuilder 能够为可以为 null 的列正确地生成 Update 语句。This allows OracleCommandBuilder to correctly generate Update statements for nullable columns.

SourceVersion

获取或设置在加载 DataRowVersion 时使用的 ValueGets or sets the DataRowVersion to use when you load Value.

Value

获取或设置参数的值。Gets or sets the value of the parameter.

方法

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
ResetDbType()

重置与此 OracleParameter 关联的类型。Resets the type associated with this OracleParameter.

ResetOracleType()

重置与此 OracleParameter 关联的类型。Resets the type associated with this OracleParameter.

ToString()

获取一个包含 ParameterName 的字符串。Gets a string that contains the ParameterName.

显式接口实现

ICloneable.Clone()

有关此成员的说明,请参见 Clone()For a description of this member, see Clone().

IDataParameter.SourceVersion (继承自 DbParameter)
IDbDataParameter.Precision

指示数值参数的精度。Indicates the precision of numeric parameters.

(继承自 DbParameter)
IDbDataParameter.Scale

有关此成员的说明,请参阅 ScaleFor a description of this member, see Scale.

(继承自 DbParameter)

适用于