Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Oracle trigger learning record

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. This is the rule of oracle and cannot operate on tables that execute triggers.

You can operate on new.xxx, but for oracle row-level triggers (for each row), you cannot do any operations on this table, including reading

Principles:

Access to this table can be achieved in before insert triggers

Access to this table cannot be implemented in after insert triggers

Access to this table cannot be realized in before/after update/delete triggers.

In fact, the reason is very simple, just to prevent dirty reading.

2. When writing oracle row-level triggers, the table cannot be operated, the report * * has changed, and the trigger / function cannot be read "

The reason is obvious that row-level trigger code cannot manipulate the table, including select, which is depressing.

Of course, the solution is based on the reason, because the operation of row-level triggers is limited, only table-level triggers can be selected, but table-level triggers can not get the values of new and: old, so we can only use two kinds of triggers, and package or temporary table to assist.

First, write the required value,: new or: old, to the package or temporary table in the row-level trigger

Then the data that has been written in the package or temporary table is processed in the table-level trigger, and the data of the temporary table can be deleted according to the requirements after successful operation.

3. ORACLE trigger

The syntax for ORACLE to generate database triggers is:

Create [or replace] trigger trigger name trigger time trigger event

On table name

[for each row]

Pl/sql statement

Where:

Trigger name: the name of the trigger object. Because the trigger is automatically executed by the database

So the name is just a name and has no real use.

Trigger time: indicates when the trigger is executed. This value is desirable:

Before--- indicates that the trigger executes before the database action

After--- indicates that the issuer executes after the database action.

Trigger event: indicates which database actions trigger this trigger:

Insert: database insert triggers this trigger

Update: database modification triggers this trigger

Delete: database deletion triggers this trigger.

Table name: the table where the database trigger is located.

For each row: execute once for each row trigger of the table. If it wasn't for this,

Option, it is executed only once for the entire table.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report