Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I rollback failed SELECT statements or commit successful ones?

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");
}
like image 337
aw crud Avatar asked Mar 04 '10 15:03

aw crud


1 Answers

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.

like image 185
Quassnoi Avatar answered Sep 25 '22 10:09

Quassnoi