我已经创建了一个带有 select 语句的触发器,我想说如果这个 select 语句不返回任何行,那么在变量“辅助”中放置一个 0。我尝试使用 NVL(auxiliar,0) 但它不起作用。我怎样才能做到这一点?
SELECT NVL(salary,0) INTO auxiliar FROM BILL WHERE code=:NEW.code;
[更新]我的触发代码:
IF preCondicio THEN
KMpendents:=coalesce(SELECT rev_pendent_km
INTO KMpendents
FROM REV_PENDENT
WHERE rev_pendent_vehicle_codi=:NEW.lloguer_vehicle_codi,0);
IF KMtotals+KMpendents>=15000 THEN
SELECT venedor_codi
INTO venedorCodi
FROM venedor
WHERE venedor_alta=(
SELECT MAX(venedor_alta)
FROM venedor
WHERE venedor_delegacio_codi=(
SELECT venedor_delegacio_codi
FROM venedor
WHERE venedor_codi=:NEW.lloguer_venedor_codi));
INSERT INTO REVISIONS VALUES(:NEW.lloguer_vehicle_codi,:NEW.lloguer_dataf,KMtotals+KMpendents,venedorCodi);
IF KMpendents!=0 THEN
DELETE FROM REV_PENDENT
WHERE rev_pendent_vehicle_codi=:NEW.lloguer_vehicle_codi;
END IF;
ELSE
IF KMpendents!=0 THEN
UPDATE REV_PENDENT SET rev_pendent_km=KMtotals+KMpendents WHERE rev_pendent_vehicle_codi=:NEW.lloguer_vehicle_codi;
ELSE INSERT INTO REV_PENDENT VALUES(:NEW.lloguer_vehicle_codi,KMtotals,:NEW.lloguer_dataf);
END IF;
END IF;
END IF;
变量KMpendents相当于我在更新之前告诉的变量auxiliar 。但是 Oracle 向我显示了这些错误:
PLS-00103:在预期以下情况之一时遇到符号“,”:。( * @ % & - + ; / at for mod 余数 rem 和或有相交的组减去顺序 start union where connect || indicator multiset