Solved

ORA-06519: active autonomous transaction detected and rolled back

Posted on 2006-06-12
6
4,469 Views
Last Modified: 2007-12-19
I keep getting this message in a package i created...
here is the pkg

CREATE OR REPLACE PACKAGE pkg_check_po
AS
   FUNCTION check_po_amount (p_invoice_id NUMBER, p_unid NUMBER)
      RETURN NUMBER;

   PROCEDURE change_approver (p_invoice_id IN NUMBER);

   PROCEDURE add_note (
      p_invoice_id   IN   NUMBER,
      p_unid         IN   NUMBER,
      p_status_id    IN   NUMBER,
      p_note         IN   VARCHAR2
   );
END;
/
----------------------
AND THE PKG BODY
-----------------------

/* Formatted on 2006/06/12 15:50 (Formatter Plus v4.8.5) */
CREATE OR REPLACE PACKAGE BODY pkg_check_po
AS
   FUNCTION check_po_amount (p_invoice_id NUMBER, p_unid NUMBER)
      RETURN NUMBER
   IS
      PRAGMA AUTONOMOUS_TRANSACTION;

      CURSOR po_check_cursor
      IS
         SELECT *
           FROM invoice_coding
          WHERE invoice_id = p_invoice_id AND coding_type_id = 3;

      po_check_row                 po_check_cursor%ROWTYPE;
      v_needs_different_approval   NUMBER                    := 0;
      v_amount_available           NUMBER                    := NULL;
   BEGIN
      OPEN po_check_cursor;

      LOOP
         FETCH po_check_cursor
          INTO po_check_row;

         EXIT WHEN po_check_cursor%NOTFOUND;

         SELECT NVL (po_line_amount_avail (po_check_row.po_number,
                                           po_check_row.po_line_id
                                          ),
                     0
                    )
           INTO v_amount_available
           FROM DUAL;

         DBMS_OUTPUT.put_line (   po_check_row.amount
                               || 'mmmmm'
                               || v_amount_available
                              );

         IF po_check_row.amount > v_amount_available
         THEN
            v_needs_different_approval := 1;
--          change_approver (p_invoice_id);
            pkg_check_po.add_note
               (p_invoice_id,
                p_unid,
                9,
                   'PO Line '
                || po_check_row.po_line_number
                || ' for PO Number '
                || po_check_row.po_number
                || ' was coding to an amount greater than the amount available for that line.'
               );
         END IF;
      END LOOP;

      CLOSE po_check_cursor;

      RETURN v_needs_different_approval;
   EXCEPTION
      WHEN OTHERS
      THEN
         RAISE;
   END;

   PROCEDURE change_approver (p_invoice_id IN NUMBER)
   AS
      PRAGMA AUTONOMOUS_TRANSACTION;
      v_new_approver   NUMBER := NULL;
-- this is who the invoice will go to so they can revise the PO
   BEGIN
      SELECT unid
        INTO v_new_approver
        FROM po_overage_approver;

      UPDATE invoices
         SET pending_approval_from_unid = v_new_approver,
             status_id = 9
       WHERE invoice_id = p_invoice_id;

      COMMIT;
   END;

   PROCEDURE add_note (
      p_invoice_id   IN   NUMBER,
      p_unid         IN   NUMBER,
      p_status_id    IN   NUMBER,
      p_note         IN   VARCHAR2
   )
   AS
      PRAGMA AUTONOMOUS_TRANSACTION;
   BEGIN
      INSERT INTO invoice_notes
                  (invoice_id, notes, unid, status_id, note_timestamp
                  )
           VALUES (p_invoice_id, p_note, p_unid, p_status_id, SYSDATE
                  );

      COMMIT;
   END;
END;
/

I dont know why it keeps occurring...i tried taking out the items i thought were causing it but i still get the error
0
Comment
Question by:jduawa
  • 2
  • 2
  • 2
6 Comments
 
LVL 25

Accepted Solution

by:
jrb1 earned 500 total points
Comment Utility
Do you need the AUTONOMOUS_TRANSACTION in check_po_amount?  If you do, try a commit before the end of the procedure--after the line

CLOSE po_check_cursor;
0
 
LVL 1

Author Comment

by:jduawa
Comment Utility
I am not sure where i need the autonomous transaction pragmas...I am not sure what it even does, I am trying to understand more behind the error, so i know how to handle it in the future...I am not sure which transaction it thinks is autonomous
0
 
LVL 25

Expert Comment

by:jrb1
Comment Utility
Every block that uses the autonomous_transaction needs to have a commit or rollback before leaving that block.

You might want to read this:

http://asktom.oracle.com/~tkyte/autonomous/index.html

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 16

Expert Comment

by:MohanKNair
Comment Utility
>> I keep getting this message in a package i created...

What is the Error message?
0
 
LVL 1

Author Comment

by:jduawa
Comment Utility
>> I keep getting this message in a package i created...

>>>What is the Error message?

ORA-06519: active autonomous transaction detected and rolled back
0
 
LVL 16

Expert Comment

by:MohanKNair
Comment Utility
>> FUNCTION check_po_amount (p_invoice_id NUMBER, p_unid NUMBER)

As jrb1 pointed out, rollback/commit is missing in

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now