oracle - 在我的触发器 ORACLE 中插入时出现错误“找不到数据”
问题描述
我有三张桌子:
create table person(
id_per number(1) primary key not null,
name_per varchar(15) not null);
create table training(
id_training number(1) primary key not null,
start_training date not null,
final_training date not null);
create table training_person(
id_tp number(3) primary key not null,
id_per number(8) not null,
id_training number(1) not null);
我创建了一个触发器,其功能是验证如果用户有活动培训,用户不能在表 training_person 中插入......但是当我想插入一个新寄存器但该人之前没有注册任何培训时, oracle 显示以下错误:“未找到数据”。
这是我的触发器:
CREATE OR REPLACE TRIGGER VERIFY_TRAINING
BEFORE INSERT OR UPDATE ON training_person
FOR EACH ROW
DECLARE
GET_FINAL_TRAINING DATE;
GET_START_TRAINING DATE;
BEGIN
select MAX(final_training) into GET_FINAL_TRAINING
from training t join training_person x on t.id_training=x.id_training join person e on e.id_per=x.id_per
WHERE e.id_per=:new.id_per;
select start_training into GET_START_TRAINING
from training t join training_person x on t.id_training=x.id_training
where t.id_training=:new.id_training;
IF (GET_FINAL_TRAINING > GET_START_TRAINING) THEN
RAISE_APPLICATION_ERROR(-20091,'U CANT INSERT TRAINING.');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
INSERT INTO training_person values(:new.id_tp,:new.id_per,:new.id_training);
END;
我正在学习Oracle,所以我不知道这是什么问题。谢谢。
解决方案
推荐阅读
- jsf - 使用来自同一类、不同范围的许多 bean
- jquery - 使用 setInterval 暂停带有 JQuery 的幻灯片?
- vba - 如何将共享邮箱电子邮件移动到与收件箱同级的文件夹中?
- php - 使用 phpcs for VSCode,如何根据它违反的规则集更改错误的字体颜色?
- reactjs - 如何查看函数中的状态?使用钩子
- laravel - 在 siteground 路线上上传 laravel 不起作用
- azure - 如何使用 adf 重命名文件,因为它们被复制到新位置
- typescript - 使用 TypeScript,我如何扩展可以是多种类型之一的接口?
- linux - 如何仅为当前会话设置 vi 选项?
- c++ - STM32H7 External Loader 无法通过 ST link 访问外部存储器