0

我需要在 Oracle 中执行此选择语句:

(MS SQL 的 TSQL 示例):

select @maxvalue = isnull(max(MYFIELD),0) from mytable

我认为甲骨文是这样的:

select nvl(max(MYFIELD),0) into maxvalue from mytable

但是,我可以只调用在.NET 连接器 maxvalue 中加载参数的 oracle 语句,还是需要一些 BEGIN END voodoo?(我使用的是 Oracle .NET 连接器,而不是 MS 连接器。)

4

1 回答 1

2

你可以同时做(有或没有“voodoo”):

        // without voodoo

        OracleCommand ncmd = new OracleCommand("select nvl(max(MYFIELD),0) from mytable", conn);

        ncmd.CommandType = CommandType.Text;

        object r = ncmd.ExecuteScalar();

        Console.WriteLine("a: " + r);
        Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

        // with the voodoo

        ncmd.CommandText = "begin select nvl(max(MYFIELD),0) into :maxvalue from mytable; end;";
        ncmd.CommandType = CommandType.Text;

        OracleParameter res = new OracleParameter(":res", OracleDbType.Double);
        res.Direction = ParameterDirection.ReturnValue;
        ncmd.Parameters.Add(res);

        ncmd.ExecuteNonQuery();

        Console.WriteLine("b: " + res.Value);
        Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
于 2012-06-20T11:31:25.837 回答