Instead of trigger usage trap

Source: Internet
Author: User

The use trap OF the INSTEAD trigger for views associated with more than two tables, Oracle cannot tell which table should be updated, and the INSTEAD trigger meets our requirements for the view DML, the display tells Oracle which table www.2cto.com to update. Unlike other triggers, The INSTEAD trigger is not actually triggered by an event: [SQL] CREATE OR REPLACE TRIGGER trigger_name INSTEAD OF operation -- delete, update, insert, create and so on view_name FOR EACH ROW BEGIN... END; because I was not very impressed with TRIGGER, I never took the initiative to get close to her at www.2cto.com. here Think wants to emphasize that 9i's document mentioned: "INSTEAD OF triggers defin Ed in the view are dropped when a view is re-created "the consistent way of thinking is: if the underlying object is modified, recompile the upper-layer view, trigger, and stored procedure as long as the status is VALID. However, the instead of trigger is nothing more than awesome, and Oracle still has such a temper! The following experiment is used to prove this sentence [SQL] hr @ ORCL> CREATE TABLE A (ID NUMBER (5), COL VARCHAR2 (5); Table created. hr @ ORCL> create table B (ID NUMBER (5), COL VARCHAR2 (5); Table created. hr @ ORCL> create or replace view V_ AB AS 2 SELECT. ID,. col as cola, B. col as colb 3 from a, B 4 WHERE. ID = B. ID 5/View created. hr @ ORCL> create or replace trigger TRG_V_ AB 2 instead of insert on V_ AB 3 FOR EACH ROW 4 BEGIN 5 INSERT INTO A (ID, COL) VALUES (: NEW. ID,: NEW. COLA); 6 insert into B (ID, COL) VALUES (: NEW. ID,: NEW. COLB); 7 END; 8/Trigger created. hr @ ORCL> SELECT TRIGGER_NAME, TRIGGER_TYPE FROM USER_TRIGGERS; TRIGGER_NAME TRIGGER_TYPE limit TRG_V_ AB instead of hr @ ORCL> insert into V_ AB VALUES (1, 'A', 'bb '); 1 row created. hr @ ORCL> COMMIT; Commit complete. hr @ ORCL> select * from a; id col ---------- ----- 1 AA hr @ ORCL> select * from B; id col ---------- ----- 1 BB hr @ ORCL> create or replace view V_ AB AS 2 SELECT. ID, B. col as cola,. col as colb 3 from a, B 4 WHERE. ID = B. ID 5/View created. hr @ ORCL> insert into V_ AB VALUES (1, 'A', 'bb'); insert into V_ AB VALUES (1, 'A', 'bb ') * ERROR at line 1: ORA-01779: cannot modify a column which maps to a non key-preserved table hr @ ORCL> SELECT TRIGGER_NAME, TRIGGER_TYPE FROM USER_TRIGGERS; no rows selected. note: trigger and row-Level Trigger: OLD: indicates the field value before update: new: indicates the field value after update.
 

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.