执行触发器时生成错误

时间:2016-07-24 11:58:52

标签: oracle plsql oracle11g

这是一段代码:

CREATE OR REPLACE TRIGGER  "TRI_MUD_PARAMETER_VW_INS" 
INSTEAD of Insert ON MUD_PARAMETER_VW for each row
DECLARE
  v_id                                         number(10);
  v_borehole_id                                number(10);
begin 
        select SEQ_ID.nextval into v_id from dual;
        select id into v_borehole_id from EPI_BOREHOLE where UBHI=:new.UBHI;

        insert into EPI_FER_MUD_PARAMETERS (ID,LOG_DATE,TOP_DEPTH,BOTTOM_DEPTH,MUD_TYPE,MUD_WT_DENSITY,VISCOSITY,PH,RES_RM,RES_RMF,RES_RMC,FLUID_LOSS, BHT,BHT_UNIT,BHT_DEPTH,SERVICE_COMPANY,HOLE_SIZE,REMARKS,BOREHOLE_ID,INSERT_DATE,INSERT_NAME,UPDATE_DATE,UPDATE_NAME)
        values (v_id,:new.LOG_DATE,:new.TOP_DEPTH,:new.BOTTOM_DEPTH,:new.MUD_TYPE, :new.MUD_WT_DENSITY,:new.VISCOSITY,:new.PH,:new.RES_RM, :new.RES_RMF,:new.RES_RMC,:new.FLUID_LOSS, :new.BHT,:new.BHT_UNIT,:new.BHT_DEPTH,:new.SERVICE_COMPANY,:new.HOLE_SIZE,:new.REMARKS, v_borehole_id,sysdate,USER,sysdate,USER);
    END;

END;

错误: -

ORA-01403: no data found
ORA-06512: at "FER_EPINET.TRI_MUD_PARAMETER_VW_INS"
ORA-04088: error during execution of trigger 'FER_EPINET.TRI_MUD_PARAMETER_VW_INS'

1 个答案:

答案 0 :(得分:2)

“找不到数据”错误表明失败的行是:

select id into v_borehole_id from EPI_BOREHOLE where UBHI = :new.UBHI;

当没有行满足条件UBHI = :new.UBHI时会发生这种情况。

有很多方法可以修复它。目前还不清楚你可能想做什么。这是一个想法:

select max(id) into v_borehole_id
from EPI_BOREHOLE
where UBHI = :new.UBHI;

这将分配NULL的值。这将指定0

的值
select coalesce(max(id), 0) into v_borehole_id
from EPI_BOREHOLE
where UBHI = :new.UBHI;