当前位置:网站首页>Oracle writes a trigger that inserts a piece of data first and updates a field in the data

Oracle writes a trigger that inserts a piece of data first and updates a field in the data

2022-06-25 23:53:00 langmeng110

The trigger has just been used recently , In principle, it should be updated after insertion , I thought it was written in the following way , I also found many methods on the Internet , The results are not quite right . The fields that need to be updated have not been updated at all , I think it should be a logical problem :

create or replace trigger UPDATE_REDLIST_TYPE
  after insert on redlist_pass_person
  for each row
declare
  -- local variables here
  redlist_flag varchar2(10);
begin
 
 select (case
           when count(1) > 0 then
            '1'
           else
            '0'
         end)
    into redlist_flag
    from redlist_person t1
   where t1.redlist_card_no = :new.card_no;
    
update redlist_pass_person set redlist_type=redlist_flag where :old.id = :new.id;
   
end UPDATE_REDLIST_TYPE;

Found behind , It needs to be written like this :

create or replace trigger UPDATE_REDLIST_TYPE
  before insert on redlist_pass_person
  for each row
declare
  -- local variables here
  redlist_flag varchar2(10);
begin
 
 select (case
           when count(1) > 0 then
            '1'
           else
            '0'
         end)
    into redlist_flag
    from redlist_person t1
   where t1.redlist_card_no = :new.card_no;
    
  :new.redlist_type := redlist_flag;

   
end UPDATE_REDLIST_TYPE;

therefore , Write this down , And let more friends not waste a lot of time on this little problem ...

Just like what you like (* ̄︶ ̄)

原网站

版权声明
本文为[langmeng110]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206252058218706.html