文章详情

短信预约信息系统项目管理师 报名、考试、查分时间动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Postgresql 存储过程

2021-03-04 01:28

关注

Postgresql 存储过程

1、没有定义 plpsql

createlang -d tms plpgsql

2、找出不连续的SN

DROP FUNCTION IF EXISTS sn_miss(IN order_name TEXT, IN pcline TEXT);
CREATE OR REPLACE FUNCTION sn_miss(IN order_name TEXT, IN pcline TEXT) 
RETURNS TABLE(sn_series TEXT)
AS $$
DECLARE
    r RECORD;
    sn_min INTEGER := 0;
    sn_max INTEGER := 0;
    sql varchar; 
    sn_base varchar;
BEGIN
    EXECUTE 
        "select 
        min(sn) as min_sn, max(sn) as max_sn 
        from 
        burn_log 
        where 
        order_number = $1 and pc_no = $2"
        USING order_name, pcline
        INTO r;
        
    sn_base := substr(r.min_sn, 1, 12);
    sn_min := to_number(substr(r.min_sn, 13, 8), "00000000");
    sn_max := to_number(substr(r.max_sn, 13, 8), "00000000");

    return QUERY EXECUTE 
            "select 
            * 
            from 
            (select $1 || sn_series from generate_series($2, $3, 1) as t(sn_series)) as A(sn_series) 
            where 
            A.sn_series 
            not in 
            (select sn from burn_log where order_number = $4 and pc_no = $5);"
        USING  sn_base, sn_min, sn_max, order_name, pcline;
END;
$$
LANGUAGE PLPGSQL VOLATILE;

3、修复产线中不连续的SN

DROP FUNCTION IF EXISTS tms_pdline_fix(IN order_name TEXT, IN pcline TEXT);
CREATE OR REPLACE FUNCTION tms_pdline_fix(IN order_name TEXT, IN pcline TEXT) 
RETURNS TABLE(sn TEXT)
AS $$
DECLARE
    r RECORD;
    sn_min INTEGER := 0;
    sn_max INTEGER := 0;
    sql varchar; 
    sn_base varchar;
BEGIN
    EXECUTE 
        "select min(sn) as min_sn, max(sn) as max_sn from burn_log where order_number = $1 and pc_no = $2;"
        USING order_name, pcline
        INTO r;
        
    sn_base := substr(r.min_sn, 1, 12);
    sn_min := to_number(substr(r.min_sn, 13, 8), "00000000");
    sn_max := to_number(substr(r.max_sn, 13, 8), "00000000");

    EXECUTE 
        "create temp table 
        pl_sn_temp 
        as
        select 
        * 
        from 
        (select $1 || sn from generate_series($2, $3, 1) as t(sn)) as A(sn) 
        where 
        A.sn 
        not in 
        (select sn from burn_log where order_number = $4 and pc_no = $5);"
    USING  sn_base, sn_min, sn_max, order_name, pcline;
    
    for r in EXECUTE "select * from pl_sn_temp" loop
        EXECUTE
            "insert into
            burn_log 
            (order_number, pc_no, sn, times_success, dt_success) 
            values 
            ($1, $2, $3, 1, $4);"
        USING order_name, pcline, r.sn, to_timestamp(19700101);
    end loop;
    
    EXECUTE
        "UPDATE 
        pcline 
        SET 
        success_number = (
            SELECT 
            COUNT(*) 
            FROM 
            burn_log 
            WHERE 
            order_number = $1 and pc_no = $2
            )
        WHERE
        order_number = $1 and pc_no = $2"
        USING order_name, pcline;
    
    return QUERY EXECUTE "select * from pl_sn_temp";
    EXECUTE
        "DROP TABLE IF EXISTS pl_sn_temp";
END;
$$
LANGUAGE PLPGSQL VOLATILE;

4、实例

时间:2018-8-15
订单:DD07ME180709014-6
产线:2
原因:系统没有D盘,导致烧录日志无法上报系统,而出现烧录成功但后台没有记录。
解决:

insert into 
burn_log
(order_number, pc_no, sn, times_success, dt_success)
values
("DD07ME180709014-6", "2", "98.00-07.24-10163912", 1, now());

select tms_pdline_fix("DD07ME180709014-6", "2");
阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯