SELECT (select placename from sysloginplace where id = a.YardName) YardNameDisp,
               a.YardName,
               a.CntrOrUnit2,
               count(*) CntrNum,
               sum(a.labhourpg) LabHourPg,
               sum(a.labhourfp) LabHourFp,
               sum(a.cntrlabhourpf) LabHourPf,
               sum(a.labhour) LabHour,
               sum(a.matcostrmb) MatCostRMB,
               sum(a.cntrmatcostpfrmb) MatCostPfRMB
          FROM V_PM04_PGTJ a
         WHERE (a.CntrRepState in ('02', '03'))
           and a.CntrRepState = '02'
           and a.IsRentBack = '0'
           and a.CntrOrUnit2 = '3'
         group by a.YardName, a.CntrOrUnit2
         order by a.YardName, a.CntrOrUnit2上面这个语句在10g可以正常执行,但在11g数据库中执行显示报错信息:ora-01427 单行子查询返回多个行
各位如何解决???

解决方案 »

  1.   

    你返回了一个结果集。 
    set后面跟的只能是具体的数据,只能一对一的使用
    没用过11g不过报错应该原因都是差不多的
      

  2.   

    原因很有可能是下面这句话返回了多条记录:(select placename from sysloginplace where id = a.YardName) YardNameDisp
    肯定不是 10g和11g的区别,如果说11g的sql在10g上不能执行还算是个正常情况
    反过来不太可能,应该是你数据的问题。
    建议:(select min(placename) from sysloginplace where id = a.YardName) YardNameDisp
    (select max(placename) from sysloginplace where id = a.YardName) YardNameDisp
      

  3.   

    (select placename from sysloginplace where id = a.YardName) YardNameDisp,
    楼主你的错误信息 应该是这句话报出来的
    单独执行一下
    select placename from sysloginplace where id = a.YardName
    应该返回的是多条数据
      

  4.   

    ORA-01427: single-row subquery returns more than one row 
    Cause: The outer query must use one of the keywords ANY, ALL, IN, or NOT IN to specify values to compare because the subquery returned more than one row. 
    Action: Use ANY, ALL, IN, or NOT IN to specify which values to compare or reword the query so only one row is retrieved.  
      

  5.   

    应该不会出现在10g运行正常而在11g报错的情况如果可以的话你把在两个版本上的运行代码和结果贴出来看看或者你可以去确认一下sysloginplace表中的内容在你的10g和11g数据库中是否相同
    也有可能在10g中正常运行是由于数据和11g中的表不一样