如何修复ORA-00918:列定义不明确

时间:2019-03-25 12:59:13

标签: sql oracle

我是oracle sql的新手,此代码在tsql中可以使用,但在oracle sql中似乎不可用。我得到

  

ORA-00918:列含糊不清

。我找不到问题所在,您能帮忙吗?

问题似乎出在联接中,因为当我用简单的where子句替换联接时,错误消失了

WITH cte1 AS
   (select t1.CONTAINER_NUMBER        as t1_CONTAINER_NUMBER,
           t1.LAST_UPDATE_TIME        as t1_LAST_UPDATE_TIME,
           t1.TRANSACTION_TIME        as t1_TRANSACTION_TIME,
           t1.EVENT,
           t1.LINE_OPERATOR,
           t1.BOOKING_NUMBER,
           t1.ISO_SIZE_TYPE,
           t1.GROSS_WEIGHT,
           t1.CATEGORY,
           t1.STATUS,
           t1.POS_MODE,
           t1.ARR_MODE,
           t1.ARR_CARRIER,
           t1.ARR_VOYAGE,
           t1.DEP_CARRIER,
           t1.DEP_MODE,
           t1.DEP_CARRIER,
           t1.LOAD_PORT,
           t1.DESTINATION_PORT,
           t1.TRUCKER_LICENSE,
           t1.FROM_RAILCAR_NAME,
           t1.TO_RAILCAR_NAME,
           t1.YARDARRIVAL_TIME,
           t1.YARDDEPARTURE_TIME,
           t1.CUSTOMER_REFERENCE,
           t1.CONTAINER_LENGTH,
           t1.CONTAINER_WIDTH,
           t1.CONTAINER_HEIGHT,
           t1.TERMINAL_ARRIVAL_TIME,
           t1.TERMINAL_DEPARTURE_TIME
      from CONTAINER_HISTORY_MVW t1
     where t1.CONTAINER_NUMBER = 'BEAU2105501'
       and t1.EVENT is not null),
  cte2 AS
   (select t2.CONTAINER_NUMBER      as t2_CONTAINER_NUMBER,
           t2.LAST_UPDATE_TIME      as t2_LAST_UPDATE_TIME,
           t2.TRANSACTION_TIME      as t2_TRANSACTION_TIME,
           t2.CREATION_TIME,
           t2.EQUIPMENT_MOVE_TYPE,
           t2.FROM_EQUIPMENT_NUMBER
      from CONTAINER_HISTORY_MVW t2
     where t2.CONTAINER_NUMBER = 'BEAU2105501'
       and t2.EVENT is null)
  SELECT cte1.t1_TRANSACTION_TIME,
         cte1.t1_CONTAINER_NUMBER,
         cte1.t1_LAST_UPDATE_TIME,
         cte1.EVENT,
         cte1.BOOKING_NUMBER,
         cte2.t2_TRANSACTION_TIME,
         cte2.CREATION_TIME,
         cte2.EQUIPMENT_MOVE_TYPE,
         cte2.FROM_EQUIPMENT_NUMBER
    from cte1
   inner join cte2
      on cte1.t1_CONTAINER_NUMBER = cte2.t2_CONTAINER_NUMBER
     and cte1.t1_LAST_UPDATE_TIME = cte2.t2_LAST_UPDATE_TIME
   order by cte1.t1_TRANSACTION_TIME, cte2.t2_TRANSACTION_TIME

2 个答案:

答案 0 :(得分:4)

最有可能发生剪切和粘贴错误,但只能选择一次列,或者您必须对第二个列起别名,以区别于第一列。

       t1.DEP_CARRIER,
       t1.DEP_MODE,
       t1.DEP_CARRIER,    -- duplicate column name in cte1

答案 1 :(得分:0)

我会说这是因为您在列中输入了“ ..” 尝试在WITH查询之外设置列的格式。