oracle 10g通过抛出具有相同列数的异常来选择组

时间:2015-01-08 14:12:25

标签: oracle

 select 
        case when exists (select "CreatedOn" dategn from "RentedVehicle" where "fkTempVehicleId"=3) 
        then 
        case when exists (select "CreatedOn" dategn from "Transfer" where "fkTempVehicleId"=3) 
        then 
           (select 
           case when rent.dategn>tran.dategn then rent.dategn else tran.dategn end dategn,
           case when rent.dategn>tran.dategn then rent.fuel else tran.fuel end fuel
           from 
              (
               select max("CreatedOn") dategn,"CheckInFuel" fuel 
               from "RentedVehicle" where "fkTempVehicleId"=3 
               group by "RentedVehicle"."CheckInFuel"
              ) rent ,
        (select max("CreatedOn") dategn,"fkFuelLevelId" fuel 
        from "Transfer" where "fkTempVehicleId"=3 group by "Transfer"."fkFuelLevelId") tran) 
        else 
        (select
         max("CreatedOn") dategn,"CheckInFuel" fuel 
        from "RentedVehicle" where "fkTempVehicleId"=3 group by "RentedVehicle"."CheckInFuel") end 
        else 
        case when exists (select "CreatedOn" dategn from "Transfer" where "fkTempVehicleId"=3) 
        then 
        (select max("CreatedOn") dategn,"fkFuelLevelId" fuel 
        from "Transfer" where "fkTempVehicleId"=3 group by "Transfer"."fkFuelLevelId") 
        else 
        (select "CreatedOn" dategn,"InitialFuel" fuel from "TempVehicle" where "pkTempVehicleId"=3) 
        end end  from dual;

它正在抛出异常

ORA-00913: too many values
00913. 00000 -  "too many values"
*Cause:    
*Action:
Error at Line: 6 Column: 2

我确信我错过了一些东西,但我几乎尝试了一切。 请帮助并详细说明我错过的内容

1 个答案:

答案 0 :(得分:2)

您的内联选择(case语句的一部分)会返回两个值(dategnfuel),其中只允许一个:

...
then 
(select 
case when rent.dategn>tran.dategn then rent.dategn else tran.dategn end dategn,
case when rent.dategn>tran.dategn then rent.fuel else tran.fuel end fuel
from ...

case每行只能返回一个值(因为每行调用一次)。