您好,登錄后才能下訂單哦!
這篇文章主要講解了“數據庫觸發器舉例分析”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“數據庫觸發器舉例分析”吧!
我們維護一張客戶表,這張表的內容在周六和周日不允許修改。這就是客戶表:
CREATE TABLE plch_customers ( custnum INTEGER , custname VARCHAR2 (100) )
我需要創建一個觸發器來阻止周末對這張表的任何插入、修改和刪除。我寫了這些代碼:
CREATE OR REPLACE TRIGGER plch_customers_maint_trg /*TEXT*/ DECLARE BEGIN 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; /
哪些選項可用來取代文中的/*TEXT*/, 使得這個觸發器不允許周末對plch_customers表執行任何DML操作,并且每個語句只觸發一次?
(A)
BEFORE UPDATE ON plch_customers FOR EACH ROW BEFORE INSERT ON plch_customers FOR EACH ROW BEFORE DELETE ON plch_customers FOR EACH ROW
SQL> CREATE OR REPLACE TRIGGER plch_customers_maint_trg BEFORE UPDATE ON plch_customers FOR EACH ROW BEFORE INSERT ON plch_customers FOR EACH ROW BEFORE DELETE ON plch_customers FOR EACH ROW DECLARE BEGIN 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: 無效的觸發器說明 SQL>
(B)
BEFORE UPDATE ON plch_customers BEFORE INSERT ON plch_customers BEFORE DELETE ON plch_customers
SQL> CREATE OR REPLACE TRIGGER plch_customers_maint_trg BEFORE UPDATE ON plch_customers BEFORE INSERT ON plch_customers BEFORE DELETE ON plch_customers DECLARE BEGIN 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: 無效的觸發器說明 SQL>
(C)
BEFORE UPDATE, INSERT OR DELETE ON plch_customers
SQL> CREATE OR REPLACE TRIGGER plch_customers_maint_trg BEFORE UPDATE, INSERT OR DELETE ON plch_customers DECLARE BEGIN 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: 缺失 ON 關鍵字 SQL>
(D)
BEFORE UPDATE OR INSERT OR DELETE ON plch_customers FOR EACH ROW
SQL> Trigger created SQL>
(E)
BEFORE UPDATE OR INSERT OR DELETE ON plch_customers
SQL> Trigger created SQL>
答案E
D不是答案因為每行都會觸發,不滿足條件。
感謝各位的閱讀,以上就是“數據庫觸發器舉例分析”的內容了,經過本文的學習后,相信大家對數據庫觸發器舉例分析這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。