不能增加重复客商的trigger|感谢一路的提醒|

create or replace trigger ADDCSUTSAME
  before insert on bd_cubasdoc
  for each row
declare
  -- local variables here
  pk_bas  varchar2(200);
  cursor basjob(id varchar2)is
  select custname from bd_cubasdoc
  where custname=id
  and nvl(dr,0)=0
  and custname in (select custname from bd_cubasdoc)
  /*and length(custname)>3*/;
begin
 open basjob(:new.custname) ;
 loop
   fetch basjob
   into pk_bas;
  exit when basjob%notfound;
  end loop;
   close basjob;
  if pk_bas is not null then
    begin
      raise_application_error(-20001,pk_bas||'客商名称重复,请直接修改已存在客商增行!');
      end;
      end if;
end ADDCSUTSAME;

一直在用这个触发器,本来是要让一路提意见:游标定义中使用了and custname in (select custname from bd_cubasdoc),以后随着客商数据的增加,会不会导致软件端操作低效率,因为单纯查询(select custname from bd_cubasdoc)就会耗时2.188s(目前有近一万的客商)

没有想到一路一看到了我这个游标的问题,and custname in (select custname from bd_cubasdoc)这句话是可以不要的。因为前面已经有了select custname from bd_cubasdoc

 

原文地址:https://www.cnblogs.com/sumsen/p/2583057.html