Skip to main content

Avoid COMMIT/ROLLBACK calls in database objects

ZPA rule for PL/SQL and Oracle SQL · CommitRollback

A transaction belongs to whoever starts it: the application, the job or the client that calls the subprogram. A COMMIT or ROLLBACK inside a stored subprogram or trigger ends the caller's transaction too, so the caller can no longer undo its own work, or loses it, and the subprogram cannot be reused inside a larger transaction.

This rule reports COMMIT and ROLLBACK in stored code. It does not report ROLLBACK TO SAVEPOINT, which undoes only the subprogram's own work, code in anonymous blocks and scripts, nor code in a subprogram or trigger declared with PRAGMA AUTONOMOUS_TRANSACTION, whose transaction is its own.

Examples​

Noncompliant Code Example
create procedure move_crate(p_crate in number, p_rack in number) is
begin
update crate set rack_id = p_rack where id = p_crate;
commit; -- Noncompliant
end;
Compliant Solution
create procedure move_crate(p_crate in number, p_rack in number) is
begin
update crate set rack_id = p_rack where id = p_crate;
end;