OracleCommand.ExecuteOracleScalar 方法
定义
执行查询,并将查询返回的结果集中第一行的第一列作为 Oracle 特定的数据类型返回。Executes the query, and returns the first column of the first row in the result set returned by the query as an Oracle-specific data type. 忽略其他列或行。Extra columns or rows are ignored.
public:
System::Object ^ ExecuteOracleScalar();
public object ExecuteOracleScalar ();
member this.ExecuteOracleScalar : unit -> obj
Public Function ExecuteOracleScalar () As Object
返回
结果中第一行的第一列会被设置为特定于 Oracle 的数据类型,或者,如果结果为 REF CURSOR,则为 null 引用。The first column of the first row in the result set as an Oracle-specific data type, or a null reference if the result is a REF CURSOR.
注解
使用 ExecuteOracleScalar 方法检索单个值 (例如,从数据库) 聚合值。Use the ExecuteOracleScalar method to retrieve a single value (for example, an aggregate value) from a database. 这需要比使用方法更少的代码 ExecuteReader ,然后执行必要的操作,以便根据返回的数据生成单个值 OracleDataReader 。This requires less code than using the ExecuteReader method, and then performing the operations necessary to generate the single value from the data returned by an OracleDataReader.
典型的 ExecuteOracleScalar 查询可以设置为以下 c # 示例中的格式:A typical ExecuteOracleScalar query can be formatted as in the following C# example:
command.CommandText = "SELECT COUNT(*) AS NumberOfRegions FROM Region";
count = command.ExecuteOracleScalar();