PLSQL Trigger ORA 01403 no data found

眉间皱痕 提交于 2019-12-25 19:57:08

问题


i am making a trigger in PL-SQL to restrict employees in section/dept on my employee entry form i get ORA-01403: no data found . please anyone help me

create or replace trigger DEPT_STRENTH
  after insert on empmasterinfo
  for each row
DECLARE
  -- local variables here
  EMP_Count        NUMBER;
  MAX_Strength     NUMBER;
  V_Mainid         VARCHAR2(100);
  V_orgelementname VARCHAR2(100);
BEGIN

--taking value from form

 V_Mainid         := :new.mainid;
  V_orgelementname := :new.orgelementname;

--Comparing values with existing 

  select d.strength
    into MAX_Strength
    from dept_strength d 

-- Master table 


 where d.Mainid = V_Mainid
     and d.orgelementname = V_orgelementname;

  select count(e.employeeid)
    into EMP_Count

-- Master table 


 from empmasterinfo e 
   where e.emp_status = 0
     and e.Mainid = V_Mainid
     and e.orgelementname = V_orgelementname;

  if EMP_Count >= MAX_Strength then

    RAISE_APPLICATION_ERROR(-20101,
                            'Maximum Number of Employees in Department Reached');

  end if;

end DEPT_STRENTH;

回答1:


This is an exercise in debugging your code.

Step one is to look at what you have written. The NO_DATA_FOUND exception is thrown by a query which returns no rows. You have two queries in your trigger. However aggregation queries don't raise that exception, as the count will return 0.

So only one query can be hurling ORA-01403, which clearly indicates you don't have any rows in dept_strength that match the rows you're inserting in empmasterinfo. Presumably you think you should have rows in that table, in which case you need to revisit your transactional logic.

You should probably do that anyway, as trying to enforce this sort of business rule in a trigger is a bad mistake. It doesn't scale and it doesn't work in multi-user environments.



来源:https://stackoverflow.com/questions/20160040/plsql-trigger-ora-01403-no-data-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!