我正在数据库中创建一个触发器,遇到了两个我无法修复的错误,我很确定这两个错误与我对 DBMS_OUTPUT.PUT_LINE 的使用有关,语句的其余部分没有导致任何错误,尽管以前有过。

错误:



码:

CREATE TRIGGER INVOICES
BEFORE INSERT OR UPDATE ON BRUINVOICE
FOR EACH ROW
BEGIN
  IF :new.BRU_DATE < :new.BRU_PAID_DATE THEN
  DBMS_OUTPUT.PUT_LINE('You cannot do that');
  ELSE
  INSERT INTO table BRUINVOICE
  values
  from inserted;
END IF;
END;

最佳答案

在记录级别验证方面,检查约束比触发器更好(在性能方面):

ALTER TABLE bruinvoice
ADD CONSTRAINT validate_bru_date CHECK (BRU_DATE < BRU_PAID_DATE);

插入无效数据将引发如下错误消息:
scott@ORCL> insert into bruinvoice values ('21-DEC-14','20-DEC-14');
insert into bruinvoice values ('21-DEC-14','20-DEC-14')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.VALIDATE_BRU_DATE) violated

关于sql - Oracle SQL触发器-DBMS_OUTPUT.PUT_LINE,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28179312/

10-16 10:37