zoukankan      html  css  js  c++  java
  • 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差不多。

  • 相关阅读:
    [Erlang05]gen_server怎么去写eunit?
    [Erlang04]为什么有了rpc还有net_kernel:connect/1?
    [Erlang03]Erlang有哪些好用的静态分析工具?
    [SIP01]SIP Header Fields里面各字段用途
    [SIP00]SIP 概念总结
    [Erlang00]:gen_server:reply/2
    Makefile教程
    Linux 环境下开发 STM32
    Ubuntu 18.04 + ROS Melodic + TurtleBot3仿真
    Ubuntu系统鼠标不能点击
  • 原文地址:https://www.cnblogs.com/miaoying/p/8494961.html
Copyright © 2011-2022 走看看