首页 > 解决方案 > 在我的触发器 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,所以我不知道这是什么问题。谢谢。

标签: oracleoracle11g

解决方案


推荐阅读