OracleParameter OracleParameter OracleParameter OracleParameter Class

定义

表示 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 OracleParameterCollectionOracleDataAdapter通过创建多个的实例。The following example creates multiple instances of OracleParameter through the OracleParameterCollection within the OracleDataAdapter. 这些参数用于从数据库中选择数据,并将数据放入中DataSetThese parameters are used to select data from the database and place the data in the DataSet. 此示例假设已使用DataSet相应的OracleDataAdapter架构、命令和连接创建了一个和。This 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() OracleParameter() OracleParameter()

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

OracleParameter(String, Object) OracleParameter(String, Object) OracleParameter(String, Object) 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(String, OracleType) OracleParameter(String, OracleType) 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(String, OracleType, Int32) OracleParameter(String, OracleType, Int32) 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(String, OracleType, Int32, ParameterDirection, Boolean, Byte, Byte, String, DataRowVersion, Object) OracleParameter(String, OracleType, Int32, ParameterDirection, Boolean, Byte, Byte, String, DataRowVersion, Object) 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(String, OracleType, Int32, ParameterDirection, String, DataRowVersion, Boolean, Object) OracleParameter(String, OracleType, Int32, ParameterDirection, String, DataRowVersion, Boolean, Object) 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(String, OracleType, Int32, String) OracleParameter(String, OracleType, Int32, String) 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 DbType DbType DbType

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

Direction Direction Direction 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 IsNullable IsNullable IsNullable

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

Offset Offset Offset Offset

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

OracleType OracleType OracleType OracleType

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

ParameterName ParameterName ParameterName ParameterName

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

Precision Precision Precision Precision

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

Scale Scale Scale Scale

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

Size Size Size Size

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

SourceColumn SourceColumn SourceColumn 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 SourceColumnNullMapping SourceColumnNullMapping SourceColumnNullMapping

设置或获取一个值,该值指示源列是否可以为 null。Sets or gets 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 SourceVersion SourceVersion SourceVersion

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

Value Value Value Value

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

方法

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

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

(Inherited from MarshalByRefObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

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

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

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

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

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

(Inherited from MarshalByRefObject)
ResetDbType() ResetDbType() ResetDbType() ResetDbType()

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

ResetOracleType() ResetOracleType() ResetOracleType() ResetOracleType()

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

ToString() ToString() ToString() ToString()

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

显式界面实现

ICloneable.Clone() ICloneable.Clone() ICloneable.Clone() ICloneable.Clone()

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

适用于