Research on nested transaction invocation of Oracle database for data integrity

Source: Internet
Author: User
Tags rollback oracle database
oracle| Data | database
In order to protect the integrity of the data we used a lot of methods, such as data table primary key constraints, external

Key constraints, triggers, and so on, what we're talking about today is when we're dealing with data direct transactions

Wait, save the integrity of the data, for example, in a stored procedure I proc_savebill save a

Document, call a function Func_generatecode to generate a document number, if I

This function is taken from a table that has the largest number and adds a number to it, and you can

The problem that can be imagined is that if I pass the Proc_savebill before saving

Over Func_generatecode get a number, if the save after the unsuccessful, how to do is not

is to lose a number, because I call once Func_generatecode will add a number

, so in order to make our data complete without losing a single, the use of the transaction will roll, now

Again, the stored procedure rolls into the function! The answer is, if there is a transaction in the function or

There is a commit statement, then it will not roll, otherwise you can roll, because the transaction will roll to the

All things after a committ or rollback. So here's what I'm trying to say to remind big

Home some methods that consider the nested rollback of a transaction. However, during a stored procedure call stored procedure, such as

There is no error in executing the stored procedure that is invoked, so it is regrettable that it will not roll. In order to solve

This problem Oracle uses autonomous transactions to deal with the above problems, in the is\as of the stored procedure

The following statement pragma autonomous_transaction; --autonomous transactions prevent nested commits, so that

Committing or rolling back a transaction within its own transaction area does not affect other transactions.

Today is here to say these, of course, these are relatively basic, for beginners to mention a wake up!



Related Article

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.