这篇文章主要讲解了“数据库触发器举例分析”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“数据库触发器举...
这篇文章主要讲解了“数据库触发器举例分析”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“数据库触发器举例分析”吧!
我们维护一张客户表,这张表的内容在周六和周日不允许修改。这就是客户表:
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不是答案因为每行都会触发,不满足条件。
感谢各位的阅读,以上就是“数据库触发器举例分析”的内容了,经过本文的学习后,相信大家对数据库触发器举例分析这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是捷杰建站,小编将为大家推送更多相关知识点的文章,欢迎关注!