• 触发器


    CREATE OR REPLACE TRIGGER trg_quote_otherArea_to_list
    before insert or delete or update of modify_date on tab_quote_other_area
    for each row
    declare
    integrity_error exception;
    errno integer;
    errmsg char(200);
    str varchar(2000);
    begin

    if inserting then
    --取序列号
    begin
    IF :new.other_area_id is null or :new.other_area_id=0 THEN
    select sequence_other_area.nextval INTO :new.other_area_id from dual;
    END IF;
    exception
    when integrity_error then raise_application_error(errno, errmsg);
    end;

    if :new.other_area_site_code is not null then
    insert into tab_quote_other_list
    (guid,other_area_id ,use_site_code ,fee_type_code ,other_site_code ,modify_date)
    select sys_guid(),:new.other_area_id,:new.use_site_code,:new.fee_type_code,
    substr(other_area_site,
    instr(other_area_site, ';', 1, rownum) + 1,
    instr(other_area_site, ';', 1, rownum + 1) -
    instr(other_area_site, ';', 1, rownum) - 1),sysdate
    from (select :new.other_area_site_code as other_area_site from dual)
    --正则表达式查找";"的个数
    connect by rownum < length(regexp_replace(other_area_site, '[^;]',''));
    --函数替换(数据量小)translate(string,from_str,to_str),同时比较string和from_str
    --字符串中的每个字符,存在不存在to_str字符,即从string中剔除掉
    --connect by rownum < length(translate(other_area_site,';' || other_area_site,';'));
    end if;
    elsif deleting then
    if :old.other_area_site_code is not null then
    delete from tab_quote_other_list where other_area_id = :old.other_area_id;
    end if;
    else
    if nvl(:old.modify_date,to_date('1899-1-1 00:00:00', 'yyyy-mm-dd hh24:mi:ss')) <>
    nvl(:new.modify_date,to_date('1899-1-1 00:00:00', 'yyyy-mm-dd hh24:mi:ss')) then

    if :old.other_area_site_code is not null then
    delete from tab_quote_other_list where other_area_id = :old.other_area_id;
    end if;
    if :new.other_area_site_code is not null then
    insert into tab_quote_other_list
    (guid,other_area_id ,use_site_code ,fee_type_code ,other_site_code ,modify_date)
    select sys_guid(),:new.other_area_id,:new.use_site_code,:new.fee_type_code,
    substr(other_area_site,
    instr(other_area_site, ';', 1, rownum) + 1,
    instr(other_area_site, ';', 1, rownum + 1) -
    instr(other_area_site, ';', 1, rownum) - 1),
    sysdate
    from (select :new.other_area_site_code as other_area_site from dual)
    connect by rownum < length(translate(other_area_site,';' || other_area_site,';'));
    end if;

    end if;
    end if;
    end trg_quote_otherArea_to_list;

  • 相关阅读:
    SAMBA服务和FTP服务讲解(week3_day1)--技术流ken
    Linux网络技术管理及进程管理(week2_day4)--技术流ken
    RAID磁盘阵列及CentOS7系统启动流程(week2_day3)--技术流ken
    Linux磁盘管理及LVM讲解(week2_day2)--技术流ken
    Linux计划任务及压缩归档(week2_day1)--技术流ken
    Linux权限管理(week1_day5)--技术流ken
    Linux高级命令进阶(week1_day2)--技术流ken
    k8s集群监控(十一)--技术流ken
    k8s部署使用Dashboard(十)--技术流ken
    k8s应用机密信息与配置管理(九)--技术流ken
  • 原文地址:https://www.cnblogs.com/yangpeng-jingjing/p/9081174.html
Copyright © 2020-2023  润新知