在'emprunter'表上创建一个触发器时,我试图比较来自另一个表'exemplaire.numexemplaire'的值,它应该是一个INTEGER。但我一直得到同样的错误:
如何检索来自另一个表的字段的值(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.
答案 0 :(得分:1)
您想加入两个表:
#!/bin/sh
exec /usr/bin/ssh -o UserKnownHostsFile=/dev/null
StrictHostKeyChecking=no -i /home/ec2-user/.ssh/id_rsa "$@"
此外,上述连接查询可能会返回多行,并且调用将导致异常(截至目前未被捕获)
ORA-01422:精确提取返回超过请求的行数
答案 1 :(得分:1)
我想您想使用:new
来访问触发触发器的记录:
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 :new.numexemplaire = exemplaire.numexemplaire;
IF livreEmpruntable != 1 THEN
raise_application_error(-20000, 'exemplaire non empruntable');
END if;
END;