• postgresql存储过程


    1.为了防止误用,设置了一个参数operation,必须为insert时才生效;
    2.在新增操作过程中,如果抛出异常中断,会回滚。
     
    CREATE OR REPLACE FUNCTION fun_insert_into_tb_sys_vul_event2(operation text) RETURNS void AS
    $$
    BEGIN
        IF operation != 'insert' THEN
           RAISE EXCEPTION '参数错误!参数应该为insert!'; 
           RETURN ;
        else
        -- 为了避免重复录入,每次运行前先清空sys_vul_event表
        delete from sys_vul_event2;
        --RAISE EXCEPTION '删除失败!'; 
        --CVE披露事件 type=1
        insert into sys_vul_event2(sys_vul_id, event_date, type) select id, date_exposure, 1 as type from sys_vul where date_exposure is not NULL;
        --Google bulletin公开事件 type=2
        insert into sys_vul_event2(sys_vul_id, event_date, source, type) select id, date_bulletin, source, 2 as type from sys_vul where date_bulletin is not NULL;
        --提供修复patch事件 type=3
        insert into sys_vul_event2(sys_vul_id, event_date, type) select id, date_fixed, 3 as type from sys_vul where date_fixed is not NULL;
        --poc,exp公开事件 poc type=5;exp type=6
        insert into sys_vul_event2(sys_vul_id, event_date, type) select sys_vul_id, exposed_date, case when type='exp' then 6 when type='poc' then 5 end as type from security_matter;
        END IF;
        EXCEPTION WHEN others THEN  
        RAISE EXCEPTION '(%)', SQLERRM; 
        ROLLBACK;
    END;
    $$ LANGUAGE PLPGSQL; 

     rollback就相当于结束了,和return差不多。

  • 相关阅读:
    ecshop 调用指定分类的推荐,热卖,新品
    ecshop 首页调用指定类产品
    html常用笔记
    ecshop 修改flash图片大小
    ecshop 删除随机版权
    Java Web(一) Servlet详解!!
    Git使用总结
    git clone命令使用
    Lucene学习总结之四:Lucene索引过程分析
    Lucene学习总结之二:Lucene的总体架构
  • 原文地址:https://www.cnblogs.com/miaoying/p/8494961.html
Copyright © 2020-2023  润新知