我应该回滚失败的 SELECT 语句还是提交成功的 SELECT 语句?
出于习惯,我在应用程序代码中对所有 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 SELECT
s? 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Oracle
中的SELECT
语句(除非它们是SELECT FOR UPDATE
)永远不会锁定任何记录,也永远不会隐式打开事务。除非您在事务中发出任何
DML
操作,否则提交或回滚事务都无关紧要。SELECT
statements inOracle
(unless they areSELECT 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.