生产管理软件开发:一种生成锯齿形产品BOM的方法

用MySQL 递归方法with recursive,编写一存储过程,生成锯齿形产品BOM。参数p_product_no是一个父项物料编码。

/* 
锯齿形产品BOM显示程序PROCEDURE ident_bom(p_product_no)
programed by fuerquan,copy right 2023,2030
*/
CREATE PROCEDURE `ident_bom`(p_product_no varchar(20))
BEGIN
	declare v_qty_per decimal(6,2) default 1.0;
	declare v_wastage_rate decimal(4,2) default 0.0;
    declare v_ancestry_no varchar(100) default p_product_no;
	with recursive temp_bom(lev,ancestry_no, item_no, item_name, 
            speci, item_type, qty_per, measure, procuremode, 
            lead_time,wastage_rate,scrap_rate)
	as (
		select 0,v_ancestry_no, item_no, item_name, speci, 
                item_type, v_qty_per, measure, procuremode, 
                lead_time,v_wastage_rate,scrap_rate 
			from items
			where item_no=p_product_no
		union all 
		select lev+1,concat(t.ancestry_no,':',b.component_no), 
			    b.component_no, b.component_name,b.speci, 
                b.component_type,b.qty_per,b.measure,b.procuremode, 
                t.lead_time+b.lead_time,b.wastage_rate, b.scrap_rate
        from temp_bom as t, v_bills as b 
		where (b.item_no = t.item_no) and t.lev = lev and lev <= 10
		)
	select concat(repeat('..',lev),item_no)  as 物料编码, item_name as 名称, 
           speci as 规格, item_type as 类型, measure as 单位, qty_per as 单用量, 
		    case procuremode when 0 then "制造" when 1 then "采购" 
            when 2 then "外协" end AS 获取方式,
            lead_time as 提前期,ifnull(scrap_rate,0.0) as 废品率, 
            ifnull(wastage_rate,0) as 损耗率
    from temp_bom order by ancestry_no;
END

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值