“ORA-04073:列列表对此触发器类型无效”触发器创建错误

我想写一个触发器,然后在 IDPRODUCT=3 或 IDPRODUCT=9 AND QUANTITY

CREATE OR REPLACE TRIGGER User_defined_error
BEFORE  INSERT OF IDPRODUCT,QUANTITYON BB_BASKETITEM
FOR EACH ROW 
BEGIN
IF:NEW.IDPRODUCT=3 OR NEW.IDPRODUCT=9 AND NEW.QUANTITY<10 THEN
 DBMS_OUTPUT.PUT_LINE(' Please enter quantity greater than 10. ');
 END IF;
END;
/

错误:

Error report -
ORA-04073: column list not valid for this trigger type
04073. 00000 -  "column list not valid for this trigger type"
*Cause:    A column list was specified for a non-update trigger type.
*action:   Remove the column list.
jnx000 回答:“ORA-04073:列列表对此触发器类型无效”触发器创建错误

正如 Oracle 所说:列列表对于此触发器类型无效。省略它。

示例表和触发器:

SQL> create table bb_basketitem (idproduct number,quantity number);

Table created.

SQL> create or replace trigger user_defined_error
  2    before insert on bb_basketitem
  3    for each row
  4  begin
  5    if    (:new.idproduct = 3 or :new.idproduct = 9)
  6       and :new.quantity < 10
  7    then
  8       raise_application_error(-20000,'Please enter quantity greater than 10.');
  9    end if;
 10  end;
 11  /

Trigger created.

测试:

SQL> insert into bb_basketitem(idproduct,quantity) values (3,5);
insert into bb_basketitem(idproduct,5)
            *
ERROR at line 1:
ORA-20000: Please enter quantity greater than 10.
ORA-06512: at "SCOTT.USER_DEFINED_ERROR",line 5
ORA-04088: error during execution of trigger 'SCOTT.USER_DEFINED_ERROR'


SQL> insert into bb_basketitem(idproduct,20);

1 row created.

SQL>

列列表对 before update 触发器有意义:

SQL> create or replace trigger trg_bu_bbb
  2    before update of quantity on bb_basketitem
  3    for each row
  4  begin
  5    if    (:new.idproduct = 3 or :new.idproduct = 9)
  6       and :new.quantity < 10
  7    then
  8       raise_application_error(-20001,'Please enter quantity greater than 10.');
  9    end if;
 10  end;
 11  /

Trigger created.

SQL> update bb_basketitem set quantity = 1;
update bb_basketitem set quantity = 1
       *
ERROR at line 1:
ORA-20001: Please enter quantity greater than 10.
ORA-06512: at "SCOTT.TRG_BU_BBB",line 5
ORA-04088: error during execution of trigger 'SCOTT.TRG_BU_BBB'


SQL>
本文链接:https://www.f2er.com/33518.html

大家都在问