How to update the current table in the oralce trigger

Source: Internet
Author: User

The method for updating the current table in the oralce trigger. This article describes two problems: 1. The difference between the update trigger before and the after. 2. After A field in table A is updated, the trigger triggers the execution. In the trigger www.2cto.com [SQL] -- Create table create table TEST_UP_TRI (ID NUMBER, NAME VARCHAR2 (20 ), how to update other fields in Table A in age number (2. Example: Create a trigger for the table. The function is to set the age field to 20 when the name field changes. The trigger is as follows: [SQL] create or replace trigger testtab_up_tri before update of name on test_up_tri for each row declare begin: new. age: = 20; end; the test is shown in:

The following two questions are explained at the beginning of the article: 1. Differences between after and before. One is triggered before the record operation, and the other is triggered after the record operation. For example, a foreign key is defined between tables. When deleting a primary key, you must first Delete the foreign key table, after, after each row affected by the trigger statement is modified and corresponding integrity constraints may be applied, if the trigger restriction is not violated, the trigger action is executed for the current row. Unlike BEFORE row triggers, AFTER row triggers lock rows. Therefore, after statements such as new. age: = 20 cannot be used. 2. Use update... Set to update the table is not allowed only use: new: = ** method, if you use can be compiled through, but when executed, the following error occurs: ORA-04091: Table ZXL. TEST_UP_TRI has changed, trigger/function cannot read it ORA-06512: In "ZXL. TESTTAB_UP_TRI ", line 5ORA-04088: trigger 'zxl. error 3 during execution of TESTTAB_UP_TRI ': new: = ** or select 20 into: new. in this way, when we find a field, we can directly use select ...... Into: new. age directly updates the specified field.

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.