执行触发器语句时出现错误

I'm getting an error while excuting a trigger statement

enter image description here 创建或替换触发器 weekd_tri

BEFORE INSERT OR UPDATE ON payment

FOR EACH ROW

BEGIN

IF TO_CHAR(SYSDATE, 'D') = '1' THEN

RAISE_APPLICATION_ERROR(-20000, 'Cannot make a payment on weekends');

END IF;

END;

错误信息 ORA-06512:在“SCOTT.WEEKD_TRI”,第 3 行 ORA-04088: 触发器 'SCOTT,WEEKD_TRI 执行期间出错 你能告诉我为什么会出现这个错误以及如何解决这个错误

* *此触发器不应接受客户在 Sat/Sun 上付款,所以我编写了此触发器,但当我尝试在 Sun 上插入数据时,它触发了触发器 ORA - 20000 无法在周末付款,我无法更新值但除此之外我得到了另外两个错误 ORA-06512 & ORA:04088 **

没有“错误”,除了你自己故意制造的错误。

今天是星期几?

SQL> select to_char(sysdate, 'D') from dual;

T
-
1       --> OK, that's the value you're checking in a trigger

SQL>

样本table:

SQL> create table payment (id number);

Table created.

触发器:

SQL> create or replace trigger weekd_tri
  2    before insert or update on payment
  3    for each row
  4  begin
  5    if to_char(sysdate, 'D') = '1' then
  6       raise_application_error(-20000, 'Cannot make a payment on weekends');
  7    end if;
  8  end;
  9  /

Trigger created.

测试:

SQL> insert into payment (id) values (1);
insert into payment (id) values (1)
            *
ERROR at line 1:
ORA-20000: Cannot make a payment on weekends
ORA-06512: at "SCOTT.WEEKD_TRI", line 3
ORA-04088: error during execution of trigger 'SCOTT.WEEKD_TRI'

对;那就是 完全 你想做的事情:IF 得出结论认为今天确实是 '1' 并引发了一个错误。


如果是,例如'2' 你查过了,今天你可以插入一行:

SQL> create or replace trigger weekd_tri
  2    before insert or update on payment
  3    for each row
  4  begin
  5    if to_char(sysdate, 'D') = '2' then
  6       raise_application_error(-20000, 'Cannot make a payment on weekends');
  7    end if;
  8  end;
  9  /

Trigger created.

SQL> insert into payment (id) values (2);

1 row created.

SQL>

从你的屏幕截图来看,我看到有 3 行错误消息

  • ORA-20000 - 这是由您的逻辑引起的真正错误消息
  • ORA-6512 - 识别代码行错误的服务消息
  • ORA-4088 - 用于标识发生错误的触发器名称的另一条服务消息

所以,您得到 ora-4088 的原因是 raise_application_error 您用于触发异常的命令。这只是开发者服务消息的一部分