sql报错、ORA-01427: 单行子查询返回多个行

select * from ( 
select row_.*, rownum rownum_ from ( 
select  ids "ids" , 
procinstid "procinstid" ,
businesskey "businesskey" ,
sysordertitle "sysordertitle" ,
sysordercreator "sysordercreator" ,
startuserid "startuserid" ,
procdefid "procdefid" ,
to_char(starttime) "starttime" ,
to_char(endtime) "endtime" ,
key "key" ,
name "name",
currentinfo "currentinfo"  from ( 
select proc.id_ ids,   
proc.proc_inst_id_ procinstid,   
 proc.business_key_ businesskey,   
 (select v.TEXT_        from ACT_HI_VARINST v        where v.proc_inst_id_ = proc.proc_inst_id_        and v.NAME_ = 'sysOrderTitle') sysOrderTitle,   
 (select v.TEXT_         from ACT_HI_VARINST v         where v.proc_inst_id_ = proc.proc_inst_id_          and v.NAME_ = 'sysOrderCreator') sysOrderCreator,   
  proc.start_user_id_ startuserid,    proc.proc_def_id_ procdefid,    
  to_char(proc.start_time_,'yyyy-MM-dd hh24:mi:ss') starttime ,   to_char(proc.end_time_,'yyyy-MM-dd hh24:mi:ss') endtime ,   
  def.key_ key ,   def.name_ name,    
  (select to_char(wmsys.wm_concat(to_char(act_name_ || ':' || act.assignee_)))         from act_hi_actinst act         where act.proc_inst_id_ = proc.proc_inst_id_         and act.end_time_ is null         and act.act_type_ in ('startEvent', 'userTask')) currentinfo  
  from act_hi_procinst proc, act_re_procdef def  where proc.proc_def_id_ = def.id_  ) temp where 1=1 and temp.startuserid = 'wanghongfa' order by starttime desc ) row_ ) where rownum_ > 0 and rownum_ <= 4

分析子查询发现问题,单行子查询返回多个行

select (select v.TEXT_ from ACT_HI_VARINST v where v.proc_inst_id_ = proc.proc_inst_id_ and v.NAME_ = 'sysOrderTitle') sysOrderTitle from act_hi_procinst proc, act_re_procdef def where proc.proc_def_id_ = def.id_ ;

其中:select v.TEXT_ from ACT_HI_VARINST v where v.proc_inst_id_ = proc.proc_inst_id_ and v.NAME_ = 'sysOrderTitle',应该返回与act_hi_procinst proc, act_re_procdef def where proc.proc_def_id_ = def.id_ 一样的行数的记录,但是从图中我们可以看出PROC_INST_ID_重复出现,实例变量表多了一条记录。

 

我怎么会保存多了记录在ACT_HI_VARINST 表里面呢,原因是在重新申请环节,保存了一些关键字。

解决办法:重新申请不要保存有关键字
sysOrderTitle(是子查询条件,任务环节不要保存这个字段,不然报错--单行子查询返回多个行)
sysOrderCreator(是子查询条件,后台也要做处理,不要让其保存在任务环节)
sysOrderKey(不是子查询条件,但任务环节没有必要保存)
sysOrderDesc(不是子查询条件,任务环节也会有该字段)