【问题标题】:I need to select into a parameter through the Oracle .NET connector我需要通过 Oracle .NET 连接器选择参数
【发布时间】:2012-06-22 11:26:37
【问题描述】:

我需要在 Oracle 中做这个 select 语句:

(MS SQL 的 TSQL 示例):

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

我认为 Oracle 是这样的:

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

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

【问题讨论】:

    标签: c# sql oracle select


    【解决方案1】:

    你可以同时做(有或没有“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("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    

    【讨论】:

    • 我收到“ORA-01036: 非法变量名/编号”我使用“maxvalue”作为 Oracle 参数名。它必须是“:res”吗?我也在使用 Int32,max() 是否返回不同的类型?
    • 其实我觉得我错过了开始结束;
    猜你喜欢
    • 1970-01-01
    • 2021-04-27
    • 1970-01-01
    • 1970-01-01
    • 2020-03-12
    • 2010-10-27
    • 1970-01-01
    • 2018-05-10
    • 2020-12-22
    相关资源
    最近更新 更多