我应该回滚失败的 SELECT 语句还是提交成功的 SELECT 语句?

发布于 2024-08-24 00:48:49 字数 362 浏览 3 评论 0原文

出于习惯,我在应用程序代码中对所有 SQL 查询使用 try/catch 块,并在 catch 块的开头进行回滚。我也一直致力于那些成功的事情。这对于 SELECT 来说是必要的吗?它是否释放了数据库方面的某些东西? select 语句不会改变任何数据,因此看起来有点毫无意义,但也许有一些我不知道的原因。

例如

try {
  $results = oci_execute($statement)
  oci_commit($connection);
  return $results;
}
catch {
  oci_rollback($connection)
  throw new SqlException("failed");
}

Out of habit I've been using try/catch blocks in my application code for all SQL queries, with a rollback at the beginning of the catch block. I've also been committing those which are successful. Is this necessary for SELECTs? Does it free up something on the database side? The select statements aren't altering any data so it seems somewhat pointless, but perhaps there is some reason I'm not aware of.

e.g.

try {
  $results = oci_execute($statement)
  oci_commit($connection);
  return $results;
}
catch {
  oci_rollback($connection)
  throw new SqlException("failed");
}

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

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

发布评论

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

评论(1

一曲琵琶半遮面シ 2024-08-31 00:48:49

Oracle 中的 SELECT 语句(除非它们是 SELECT FOR UPDATE)永远不会锁定任何记录,也永远不会隐式打开事务。

除非您在事务中发出任何DML 操作,否则提交或回滚事务都无关紧要。

SELECT statements in Oracle (unless they are SELECT FOR UPDATE) never lock any records and never open transactions implicitly.

Unless you issued any DML operations within your transaction, it will not matter whether you commit or roll back your transaction.

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