开发者

Call GATHER_TABLE_STATS from .Net

I have some code that attempts to gather table statistics for a given Oracle schema and table. The code should replicate the SQL statement that looks like this:

EXEC DBMS_STATS.GATHER_TABLE_STATS(ownname=>'SchemaName', tabname=>'TableName', estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt=>'FOR ALL COLUMNS SIZE AUTO');

The C# code looks like this:

using (var connection = new OracleConnection(GetConnectionString()))
{
    connection.Open();
    using (var command = connection.CreateCommand())
    {
        command.CommandText = "DBMS_STATS.GAT开发者_JAVA百科HER_TABLE_STATS";
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add(new OracleParameter("ownname", "SchemaName"));
        command.Parameters.Add(new OracleParameter("tabname", "TableName"));
        //command.Parameters.Add(new OracleParameter("estimate_percent", "DBMS_STATS.AUTO_SAMPLE_SIZE"));
        //command.Parameters.Add(new OracleParameter("method_opt", "FOR ALL COLUMNS SIZE AUTO"));
        command.ExecuteNonQuery();
    }
    connection.Close();
}

The Oracle driver is not happy with DBMS_STATS.AUTO_SAMPLE_SIZE for obvious reasons, but I don't know why it also disallows FOR ALL COLUMNS SIZE AUTO.

Any ideas on the best way to set the estimate_percent and method_opt parameters when calling this proc from .Net?


If you are using >10G, FOR ALL COLUMNS SIZE AUTO is already the default setting.

You should be able to omit the parameter completely.


please add this property to your command

command.BindByName = **true**;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜