近期写的一个比较罗嗦的Oracle after update触发器
  xaeiTka4h8LY 2024年08月02日 96 0
CREATE OR REPLACE TRIGGER TRG_PRODUCTLIST_UPDATE
AFTER UPDATE OF ISPUBLISH
ON PRODUCTLIST
FOR   EACH   ROW
declare
   ProvideNo ProvideInfo.ProvideNo%type;
   InfoTitle ProvideInfo.InfoTitle%type;
   FarmProduct ProvideInfo.FarmProduct%type;
   FarmClass ProvideInfo.FarmClass%type;
   Amount ProvideInfo.Amount%type;
   Price ProvideInfo.Price%type;
   ProductImage Provideinfo.Productimage%type;
   Info Provideinfo.Info%type;
   Contact Provideinfo.Contact%type;
   RegionNo Provideinfo.Regionno%type;
   Region1 Provideinfo.Region1%type;  --地市
   Region2 Provideinfo.Region2%type;  --区县
   MainRegionNo Region.Pregionno%type; --地市编号
   PublicTime Provideinfo.Publictime%type;
   PublicStatus Provideinfo.Publicstatus%type;
   IsLimitDays Provideinfo.Islimitdays%type;
   InfoPri Provideinfo.Infopri%type;
   FromMode Provideinfo.Frommode%type;
   FromMobile Provideinfo.Frommobile%type;
   FromUserNo Provideinfo.Fromuserno%type;
   FromUserName Provideinfo.Fromusername%type;
   SubmitTime Provideinfo.Submittime%type;
begin
   if :New.ISPUBLISH=0 then
     delete from ProvideInfo where ProvideNo=:NEW.ProvideNo;
     delete from Productrecommend where ProvideNo=:NEW.ProvideNo;
   end if;
  
   if :New.ISPUBLISH=1 then
     select getNext_ProvideNo into ProvideNo from dual;
     InfoTitle:='供应'+:NEW.FarmProduct;
     FarmProduct:=:NEW.FarmProduct;
     FarmClass:=:NEW.FarmClass;
     Amount:=:NEW.Amount;
     Price:=:NEW.Price;
     ProductImage:=:NEW.ProductImage;
     Info:=:NEW.Info;
     select SpaceName+ContactTel into Contact from SpaceList where SpaceNo=:new.SpaceNo;
     select RegionNo,SpacePri,SpaceNo,SpaceName
     into RegionNo,InfoPri,FromUserNo,FromUserName
     from SpaceList where SpaceNo=:new.SpaceNo;
     --取区县
     select Region,PRegionNo into Region2,MainRegionNo from Region where Region.Regionno=Regionno;
     --取地市
     select Region into Region1 from region where PRegionNo=MainRegionNo;
     select sysdate into PublicTime from dual;
     PublicStatus:=1;
     IsLimitDays:=0;
     FromMode:=7;
     select mobile into FromMobile from users where SpaceNo=:new.SpaceNo;
     select sysdate into SubmitTime from dual;
    
     insert into ProvideInfo(ProvideNo,InfoTitle,FarmProduct,FarmClass,Amount,
     Price,ProductImage,Info,Contact,RegionNo,Region1,Region2,PublicTime,PublicStatus,
     IsLimitDays,InfoPri,FromMode,FromMobile,FromUserNo,FromUserName,SubmitTime)
     values(ProvideNo,InfoTitle,FarmProduct,FarmClass,Amount,
     Price,ProductImage,Info,Contact,RegionNo,Region1,Region2,PublicTime,PublicStatus,
     IsLimitDays,InfoPri,FromMode,FromMobile,FromUserNo,FromUserName,SubmitTime);
   end if;
end TRG_PRODUCTLIST_UPDATE;
 
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2024年08月02日 0

暂无评论

推荐阅读
  xaeiTka4h8LY   2024年08月09日   49   0   0 Delphioracle
xaeiTka4h8LY