我可以在 odp.net 和 Oracle 8i 中使用绑定变量吗?

发布于 2024-08-28 04:10:59 字数 991 浏览 4 评论 0原文

由于缺乏测试环境,我需要知道以下场景是否可行:

我已经安装了 Oracle Data Provider for .Net 版本 9.2.0.4。在生产中,我必须从我的 C# 应用程序与两个数据库(Oracle 8i 和 9i)进行通信。

Oracle 8i 在这种情况下支持绑定变量吗?

我可能会使用类似于以下的代码:

提前致谢!

OracleCommand cmd = con.CreateCommand();

  OracleTransaction txn = con.BeginTransaction();

  try {
    cmd.CommandText = "update MayJun2009 " +
                      "set balance = balance + :1 " +
                      "where account_id = :2";

      OracleParameter pBalance = new OracleParameter();
    pBalance.OracleDbType = OracleDbType.Int32;
    OracleParameter pAccount = new OracleParameter();
    pAccount.OracleDbType = OracleDbType.Int32;

    cmd.Parameters.Add(pBalance);
    cmd.Parameters.Add(pAccount);

    pBalance.Value = -500;
    pAccount.Value = 1;

    cmd.ExecuteNonQuery();

    pBalance.Value = 500;
    pAccount.Value = 2;

    cmd.ExecuteNonQuery();

    txn.Commit();
  }
  catch (OracleException ex) {
    txn.Rollback();
  }

due to the lack of an testing environment I need to know if the following scenario will work:

I have installed the Oracle Data Provider for .Net version 9.2.0.4. In production I'll have to communicate from my C# application with two Databases, an Oracle 8i and 9i.

Does Oracle 8i support Bind Variables in this scenario?

I'm likely to use code similar to the following:

Thanks in advance!

OracleCommand cmd = con.CreateCommand();

  OracleTransaction txn = con.BeginTransaction();

  try {
    cmd.CommandText = "update MayJun2009 " +
                      "set balance = balance + :1 " +
                      "where account_id = :2";

      OracleParameter pBalance = new OracleParameter();
    pBalance.OracleDbType = OracleDbType.Int32;
    OracleParameter pAccount = new OracleParameter();
    pAccount.OracleDbType = OracleDbType.Int32;

    cmd.Parameters.Add(pBalance);
    cmd.Parameters.Add(pAccount);

    pBalance.Value = -500;
    pAccount.Value = 1;

    cmd.ExecuteNonQuery();

    pBalance.Value = 500;
    pAccount.Value = 2;

    cmd.ExecuteNonQuery();

    txn.Commit();
  }
  catch (OracleException ex) {
    txn.Rollback();
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

折戟 2024-09-04 04:10:59

是的,该示例应该使用绑定变量,无论是 Oracle 8 还是 9i 都不重要。您可以进行数据库跟踪来进行确定。 C# 绑定的另一个示例如下:

构建 Oracle .NET 应用程序的数据提供程序

Yes, that example should be using bind variables, shouldn't matter whether it is Oracle 8 or 9i. You could do a database trace to verify for certain. Another example of binds for C# is here:

Building an Oracle Data Provider for .NET Application

善良天后 2024-09-04 04:10:59

如果您的应用程序使用 9iR2 客户端或更高版本(您的情况似乎如此),您可以连接到 Oracle8i(甚至直接 Oracle8)数据库

Providing your application is using a 9iR2 client or higher, which appears to be true in your case, you can connection to Oracle8i (or even straight Oracle8) databases.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文