Jeg har en pakkeprocedure, jeg har skrevet til dette. Jeg indsætter koden nedenfor.
For at bruge det skal du bare kalde "start_no_commit_section" med et navn, du giver. Kald derefter "end_no_commit_section" med samme navn. Hvis en commit (eller rollback) er blevet udstedt, vil opkaldet til "end_no_commit_section" give en fejl.
Desværre fortæller dette dig ikke hvor forpligtelsen skete. Hvis jeg har meget kode at se igennem, vil jeg generelt køre DBMS_HPROF på min kode og derefter lede efter en commit i HPROF-resultaterne (som vil fortælle mig det nøjagtige linjenummer).
CREATE OR REPLACE PACKAGE BODY XXCUST_TRANSACTION_UTIL AS
----------------------------------------------------------------
-- See package spec for comments
----------------------------------------------------------------
TYPE no_commit_section_t IS RECORD (local_transaction_id VARCHAR2 (200));
TYPE no_commit_sections_tab IS TABLE OF no_commit_section_t
INDEX BY VARCHAR2 (80);
g_no_commit_sections no_commit_sections_tab;
PROCEDURE start_no_commit_section (p_section_name VARCHAR2) IS
l_section no_commit_section_t;
BEGIN
l_section.local_transaction_id := DBMS_TRANSACTION.local_transaction_id (create_transaction => TRUE);
g_no_commit_sections (SUBSTR (p_section_name, 1, 80)) := l_section;
END start_no_commit_section;
PROCEDURE end_no_commit_section (p_section_name VARCHAR2) IS
l_local_transaction_id VARCHAR2 (200);
BEGIN
l_local_transaction_id := DBMS_TRANSACTION.local_transaction_id (create_transaction => TRUE);
IF l_local_transaction_id != g_no_commit_sections (SUBSTR (p_section_name, 1, 80)).local_transaction_id THEN
-- There has been a commit or a rollback in the no-commit section
raise_application_error(-20001,'A commit or rollback has been detected in "No commit" section ' || p_section_name || '.');
END IF;
EXCEPTION
WHEN no_data_found THEN
-- Caller specified a non-existent commit section
raise_application_error(-20001,'"No commit" section ' || p_section_name || ' not established.');
END end_no_commit_section;
END XXCUST_TRANSACTION_UTIL;