@@ -509,6 +509,31 @@ SELECT id, msg FROM autonomous_test WHERE id = 55 ORDER BY id;
509509 55 | boolean: false
510510(2 rows)
511511
512+ --
513+ -- Test 21: Autonomous transaction in package procedure
514+ -- Tests that PRAGMA AUTONOMOUS_TRANSACTION works inside package bodies
515+ --
516+ CREATE OR REPLACE PACKAGE test_pkg AUTHID DEFINER AS
517+ PROCEDURE pkg_test_with_params(p_id INT, p_msg TEXT);
518+ END;
519+ /
520+ CREATE OR REPLACE PACKAGE BODY test_pkg AS
521+ PROCEDURE pkg_test_with_params(p_id INT, p_msg TEXT) AS
522+ PRAGMA AUTONOMOUS_TRANSACTION;
523+ BEGIN
524+ INSERT INTO autonomous_test VALUES (p_id, p_msg, 'committed');
525+ END pkg_test_with_params;
526+ END test_pkg;
527+ /
528+ COMMIT;
529+ WARNING: there is no transaction in progress
530+ CALL test_pkg.pkg_test_with_params(76, 'package procedure test');
531+ SELECT id, msg FROM autonomous_test WHERE id = 76;
532+ id | msg
533+ ----+------------------------
534+ 76 | package procedure test
535+ (1 row)
536+
512537--
513538-- Summary: Show all test results
514539--
@@ -536,4 +561,6 @@ DROP FUNCTION outer_function(INT);
536561DROP FUNCTION test_function_numeric(NUMERIC);
537562DROP FUNCTION test_function_date(DATE, INT);
538563DROP FUNCTION test_function_boolean(INT);
564+ DROP PACKAGE BODY test_pkg;
565+ DROP PACKAGE test_pkg;
539566DROP TABLE autonomous_test;
0 commit comments