Get the App
SLTechnology News&Howtos  ›  Database  › 

An example Analysis of Database trigger

Shulou Source: shulou.com Published: 2022-05-31 15:24:41 09月17日 Update

This article mainly explains the "database trigger example analysis", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "database trigger example analysis" bar!

We maintain a customer table whose contents are not allowed to be modified on Saturdays and Sundays. This is the customer list:

CREATE TABLE plch_customers (custnum INTEGER, custname VARCHAR2)

I need to create a trigger to prevent any insertions, modifications, and deletions to this table over the weekend. I wrote this code:

CREATE OR REPLACE TRIGGER plch_customers_maint_trg / * TEXT*/DECLAREBEGIN IF TO_CHAR (SYSDATE, 'DY',' NLS_DATE_LANGUAGE=ENGLISH') IN ('SAT',' SUN') THEN RAISE_APPLICATION_ERROR (- 20000, 'Customers maintained Monday-Friday only.'); END IF;END;/

What options can be used to replace the / * TEXT*/, in the article so that this trigger does not allow any DML operations to be performed on the plch_ customers table over the weekend, and each statement is triggered only once?

(A)

BEFORE UPDATE ON plch_customers FOR EACH ROWBEFORE INSERT ON plch_customers FOR EACH ROWBEFORE DELETE ON plch_customers FOR EACH ROWSQL > CREATE OR REPLACE TRIGGER plch_customers_maint_trgBEFORE UPDATE ON plch_customers FOR EACH ROWBEFORE INSERT ON plch_customers FOR EACH ROWBEFORE DELETE ON plch_customers FOR EACH ROWDECLAREBEGIN IF TO_CHAR (SYSDATE, 'DY',' NLS_DATE_LANGUAGE=ENGLISH') IN ('SAT',' SUN') THEN RAISE_APPLICATION_ERROR (- 20000, 'Customers maintained Monday-Friday only.'); END IF END;ORA-04079: invalid trigger description SQL >

(B)

BEFORE UPDATE ON plch_customersBEFORE INSERT ON plch_customersBEFORE DELETE ON plch_customersSQL > CREATE OR REPLACE TRIGGER plch_customers_maint_trgBEFORE UPDATE ON plch_customersBEFORE INSERT ON plch_customersBEFORE DELETE ON plch_customersDECLAREBEGIN IF TO_CHAR (SYSDATE, 'DY',' NLS_DATE_LANGUAGE=ENGLISH') IN ('SAT',' SUN') THEN RAISE_APPLICATION_ERROR (- 20000, 'Customers maintained Monday-Friday only.'); END IF;END;ORA-04079: invalid trigger description SQL >

(C)

BEFORE UPDATE, INSERT OR DELETE ON plch_customersSQL > CREATE OR REPLACE TRIGGER plch_customers_maint_trgBEFORE UPDATE, INSERT OR DELETE ON plch_customersDECLAREBEGIN IF TO_CHAR (SYSDATE, 'DY',' NLS_DATE_LANGUAGE=ENGLISH') IN ('SAT',' SUN') THEN RAISE_APPLICATION_ERROR (- 20000, 'Customers maintained Monday-Friday only.'); END IF;END;ORA-00969: missing ON keyword SQL >

(D)

BEFORE UPDATE OR INSERT OR DELETE ON plch_customers FOR EACH ROWSQL > Trigger createdSQL >

(E)

BEFORE UPDATE OR INSERT OR DELETE ON plch_customersSQL > Trigger createdSQL >

Answer E

D is not the answer because each line is triggered and does not meet the condition.

Thank you for your reading, the above is the content of "Database trigger example Analysis". After the study of this article, I believe you have a deeper understanding of the database trigger example analysis of this problem. the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Triggers data databases analysis content learning customers that is answers codes keys keywords ideas situations articles more conditions knowledge points articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB Linux MySQL Docker