We help IT Professionals succeed at work.

ORA-06519: active autonomous transaction detected and rolled back

jduawa
jduawa asked
on
5,137 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
Comment
Watch Question

senior developer
CERTIFIED EXPERT
Top Expert 2005
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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
jrb1senior developer
CERTIFIED EXPERT
Top Expert 2005

Commented:
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

Top Expert 2006

Commented:
>> I keep getting this message in a package i created...

What is the Error message?

Author

Commented:
>> I keep getting this message in a package i created...

>>>What is the Error message?

ORA-06519: active autonomous transaction detected and rolled back
Top Expert 2006

Commented:
>> FUNCTION check_po_amount (p_invoice_id NUMBER, p_unid NUMBER)

As jrb1 pointed out, rollback/commit is missing in

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.