Ora-14551:cannot perform a DML operation inside a query

Source: Internet
Author: User
Tags rollback

Inserts in an Oracle function will report Ora-14551:cannot perform a DML operation inside a query

problem Reason:
Functions that write to the database (INSERT, UPDATE, DELETE, create, alter, commit) cannot be invoked simply by using SQL

Workaround:

Need to declare add pragma autonomous_transaction;


For example:
Create or Replace function update_contractdate (V_contractid in Contract.id%type, v_contractbegindatestr in varchar2)
return number
As
pragma autonomous_transaction;

PRAGMA Autonomous_transaction declared as an autonomous transaction the current function runs as a child transaction of an existing transaction, and the commit,rollback operation of the child transaction does not affect the state of the parent transaction
One or more autonomous transactions can be defined in one transaction, and autonomous transactions can be commit independently, without affecting the outer transaction, and the rollback of the same outer transaction has no effect on the autonomous transaction, and it is generally possible to consider defining an autonomous transaction as a process, called in a transaction in the outer layer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.