【发布时间】:2017-03-28 03:42:45
【问题描述】:
在“emprunter”表上创建触发器时,我试图比较来自另一个表“exemplaire.numexemplaire”的值,该表应该是一个整数。但我不断收到相同的错误:
- 错误(4,7): PL/SQL: SQL 语句被忽略
- 错误 (7,15): PL/SQL: ORA-00904: "EMPRUNTER"."NUMEXEMPLAIRE": 标识符无效
如何检索来自另一个表 (exemplaire.numexemplaire) 的字段的值?
CREATE OR REPLACE TRIGGER BIEmprunter
BEFORE INSERT OR UPDATE OF numexemplaire ON emprunter
FOR EACH ROW
DECLARE
livreEmpruntable INTEGER;
BEGIN
SELECT exemplaire.empruntable
INTO livreEmpruntable
FROM exemplaire
WHERE emprunter.numexemplaire = exemplaire.numexemplaire;
IF livreEmpruntable != 1 THEN
raise_application_error(-20000, 'exemplaire non empruntable');
END if;
END;
更新 1
感谢您的回答,但我在尝试测试触发器时不断收到此错误...
SQL Error: ORA-04098: trigger 'EQUIPE10.ABONNEMENTPASAJOUR' is invalid and failed re-validation
04098. 00000 - "trigger '%s.%s' is invalid and failed re-validation"
*Cause: A trigger was attempted to be retrieved for execution and was
found to be invalid. This also means that compilation/authorization
failed for the trigger.
*Action: Options are to resolve the compilation/authorization errors,
disable the trigger, or drop the trigger.
更新 2 再次感谢您的回答,触发器现在可以编译了。但是现在当我试图在插入值时让它工作但我一直收到错误,因为还没有数据......
INSERT INTO emprunter
VALUES (2, 1, 18, '17-02-01', null);
Error report -
SQL Error: ORA-01403: no data found
ORA-06512: at "EQUIPE10.BIEMPRUNTER", line 4
ORA-04088: error during execution of trigger 'EQUIPE10.BIEMPRUNTER'
01403. 00000 - "no data found"
*Cause: No data was found from the objects.
*Action: There was no data from the objects which may be due to end of fetch.
【问题讨论】: