一个相对较难需求的实现

前提:
某施人员(工号)会进行排班施工(有开始结束时间,同一工序持续时间不一定相同), 工序包括某几个步骤,用逗号分隔。有工号排班表,工序步骤表。

要求:
统计出排班的步骤冲突情况。具体为某一步骤会同时被3个或3个以上施工人员同时占用情况.

求输出结果: 步骤,工号(同逗号分开),冲突时间(第三个冲突开始时间) 
如下例有2个冲突
L1 N1,N2,N3 18:08:20
L4 N1,N3,N4,N7 15:25:02


想通过存过实现, 用游标遍历排班表,分组统计,count(*)>=3  插入临时表。写了半天没写出,求大神出手相助。


附:
排班表

工号 开始时间 结束时间 工序
N1 18:02:01 18:30:20 S1
N2 18:07:31 18:31:20 S2
N3 18:08:20 18:35:20 S3

N4 19:00:02 19:10:10 S4
N2 13:02:01 14:30:20 S1
N3 15:07:31 15:31:20 S2
N4 15:08:20 15:35:20 S3
N1 15:25:02 16:10:10 S4
N7 15:26:03 17:10:10 S7



工序 步骤
S1 L1,L2,L3
S2 L1,L4,L5
S3 L1,L4,L7
S4 L2,L4,L8
S7 L3,L4

冲突检测结果
步骤 工号 冲突时间
L1 N1,N2,N3 18:08:20

L4 N1,N3,N4,N7 15:25:02         --这是一个网友的需求


declare 
v_col varchar2(10);
v_col1 varchar2(20);
cursor cur is select col1,to_char(wm_concat(col)) col from (select col,regexp_substr(col1,'[^,]+',1,level) col1 from test1 connect by level <= regexp_count(col1,'[,]')+1 and rowid=prior rowid   and (prior dbms_random.value) is not null) group by col1; 
begin 
  
  for cur_r in cur loop 
    
  insert into test2  
  select cur_r.col1,col,start_date from (select  id,start_date,end_date,row_number() over(partition by rn order by start_date) rn ,wm_concat(id) over(partition by rn) col from (select  id,start_date,end_date,sum(rn) over(order by start_date) rn from 
  (select id,start_date,end_date,case when rn>0 then 0 else 1 end rn from 
  (select id,start_date,end_date,lead_end_date-start_date rn from  (select id,start_date,end_date,lag(end_date) over(order by start_date) lead_end_date from test where instr(cur_r.col,col)>=1) )))) where rn=3;
  
  commit;
 
  dbms_output.put_line(cur_r.col);
   
  end loop;
 
 end;
 /

在写语这个语句的过程中花了一段时间时间去写,感觉还是有点难度的,要很熟悉oracle的函数使用才能实现这种运用。




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值