Oracle SQL 将最小值设置为 NULL 上的 INT 字段的触发器

Oracle SQL Trigger for set min Value to INT Field on NULL

我正在尝试在 table PACKS 上设置触发器,在 INT 字段中设置最小值 - 插入新 PACK 时的 PRICE - 例如“333”。用于插入调用过程新包。 这就是触发器:

CREATE OR REPLACE TRIGGER pack_min_price
BEFORE
INSERT
ON PACKS
FOR EACH ROW
BEGIN
 IF new.PRICE < 333 THEN
 :new.PRICE := :new.PRICE + 333;
 END IF;
END;

这就是程序:

create or replace PROCEDURE newPack(
cntr IN PACKS.COUNTRY%TYPE,
trns IN PACKS.TRANSPORT%TYPE,
htl IN PACKS.HOTEL%TYPE,
extr IN PACKS.HOTELEXTRAS%TYPE,
othextr IN PACKS.OTHEREXTRAS%TYPE,
strdt IN PACKS.STARTDATE%TYPE,
enddt IN PACKS.ENDDATE%TYPE,
prc IN PACKS.PRICE%TYPE)

IS
BEGIN
  INSERT INTO PACKS 
  (COUNTRY,TRANSPORT,HOTEL,HOTELEXTRAS,OTHEREXTRAS,STARTDATE,ENDDATE,PRICE)
VALUES
  (cntr,trns,htl,extr,othextr,strdt,enddt,prc);

COMMIT;

END;

我尝试编译触发器时遇到的错误 -

Compilation failed, line 2 (10:12:41) The line numbers associated with compilation errors are relative to the first BEGIN statement. This only affects the compilation of database triggers.
PLS-00201: identifier 'NEW.PRICE' must be declaredCompilation failed, line 2 (10:12:41) The line numbers associated with compilation errors are relative to the first BEGIN statement. This only affects the compilation of database triggers.
PL/SQL: Statement ignored 

当我开始程序时 -

ORA-04098: trigger 'PROJECT160.PACK_MIN_PRICE' is invalid and failed re-validation

没有触发器,程序工作得很好。你能帮我吗?谢谢

您在 IF 语句的新实例上缺少 :。

IF :new.PRICE < 333 THEN
    :new.PRICE := :new.PRICE + 333;
END IF;