日期:2014-05-16  浏览次数:20770 次

求一个oracle 函数~~~!!
我想知道某个任务现在在哪个工段(加工中,待加工,ok),当存在多个加工中的工段,或者多个待加工中共段,
或者多个加工中和待加工中共段,就显示第一个工段名称和状态,当所有工段都完成,在工段 显示ok状态显示 ok
比如:

 aa完工 bb加工中 cc 加工中 dd 待加工 就显示 工段:bb 状态:加工中

 aa完工 bb待加工 cc 待加工 dd 待加工 就显示 工段:bb 状态:待加工

 aa完工 bb待加工 cc 加工中 dd 待加工 就显示 工段:bb 状态:待加工

 aa完工 bb完工 cc 完中 dd 完工 就显示 工段:ok 状态:待ok

现在我想写个函数 FSatue(progress in varchar2,vv1 in varchar2, vv2 in varchar2)

来判断在哪个工段和此工段的状态return a||b (a为工段名称,b为工段状态)

根据vv1,vv2查询关于vv1,vv2各个工段状态的sql:
select (select decode(t.col3,'Y','完工','N','加工中','待加工') from a t where t.col1 := vv1 and t.col2 := vv2 ) aa ,
(select decode(t.col3,'Y','完工','N','加工中','待加工') from b t where t.col1 := vv1 and t.col2 := vv2 ) bb ,
(select decode(t.col3,'Y','完工','N','加工中','待加工') from c t where t.col1 := vv1 and t.col2 := vv2 ) cc ,
(select decode(t.col3,'Y','完工','N','加工中','待加工') from d t where t.col1 := vv1 and t.col2 := vv2 ) dd 
 from dual;


然后我根据progress(函数参数颇progress);来判断应该向集合中添加那些工段名称和状态
(这就是我想问的问题,不知道oracle 中是否有想hashmap这样功能的集合)
然后遍历集合,当遍历到集合中有待加工或者加工中得纪录,就返回此工段的名称和状态,终止循环 。,如果没有的话表明所有工段OK;
返回OK||ok  




比如progress得值为'aa-bb-cc-dd',
对于上面sql查询出来的结果行,根据progress来判断是否添加到集合中
我用jsp来表达:
  Map map = new hashmap();
  if (progress.indexOf("aa") >-1){
  map .put("aa",rs.getString("aa"));
   
  }
 if (progress.indexOf("bb")>-1){
  map .put("bb",rs.getString("bb"));
   
  }
 if (progress.indexOf("cc")>-1){
  map .put("c,rs.getString("cc"));
   
  }
 if (progress.indexOf("dd")>-1){
  map .put("dd",rs.getString("d"));
   
  }

遍历集合:
Iterator it = map.iterator();
String a = "OK";
Stirng b = "OK";
while(it.hasNext()){
  String key=(String)it.next();//工段名称
  String value = map.get(key);//工段状态
  if(value.equals("加工中") ||value.equals("待加工")){
  a = key;//工段名称
  b = value ;//工段状态
  }
}
工段 <%=a%>状态<%=b%>
函数此时要return a||b就是我要的结果 
请问添加数据到集合和遍历来集合这一段在oracle 编程中怎么实现,有没有象hashMap或者数组这样的功能来实现???


   

 



------解决方案--------------------
不知道你的数据结构,没法写函数

一般对于多步骤流程的管理,是在记录中设立一个字段,专门表示该任务现在所在的位置

对于你的情况,可以加个当前工段字段,这样就容易了
------解决方案--------------------
case when aa=完工 and bb=加工中 and cc =加工中 and dd =待加工 then 工段=bb 
when aa=完工 and bb=待加工 and cc =待加工 and dd =待加工 then 工段=bb 
when aa=完工 and bb=待加工 and cc =加工中 and dd= 待加工 then 工段=bb 
else aa完工 bb完工 cc 完中 dd 完工 then 工段=ok 
end 
状态同理