尝试在 Oracle SQL 中取消透视列时出错

Getting error when trying to unpivot columns in Oracle SQL

我通过每个 table 中的同一列(称为 fema_wo)将多个 table 连接在一起。我想将所有选定的列放入一列,然后有另一列说明它来自哪个 table(与 R 的 pivot_longer() 基本相同)。当我尝试 运行 时出现错误 No more data to read from socket Vendor Code 17410 Error at line: 1; 运行 版本 CORE 11.2.0.4.0 Production Oracle

有谁知道为什么会这样以及可能的 fix/suggestion?

在此处查看代码:


select * from (

  select dpd.objectid as id1, ss.objectid as id2, ohp.objectid as id3 , ohs.objectid as id4, ugp.objectid as id5, ugs.objectid as id6,
  s.objectid as id7, t.objectid as id8
  from mvdynamicprotectivedevice dpd
  FULL OUTER JOIN mvsupportstructure ss ON (dpd.fema_wo = ss.fema_wo)
  FULL OUTER JOIN mvoverheadprimaryline ohp ON (dpd.fema_wo = ohp.fema_wo)
  FULL OUTER JOIN overheadsecondaryline ohs ON (dpd.fema_wo = ohs.fema_wo)
  FULL OUTER JOIN mvundergroundprimaryline ugp ON (dpd.fema_wo = ugp.fema_wo)
  FULL OUTER JOIN undergroundsecondaryline ugs ON (dpd.fema_wo = ugs.fema_wo)
  FULL OUTER JOIN mvswitch s ON (dpd.fema_wo = s.fema_wo)
  FULL OUTER JOIN mvtransformer t ON (dpd.fema_wo = t.fema_wo)
  WHERE dpd.fema_wo = 'WBS.F.81109.1.1.2'

)
unpivot (

  objectid
  for objectid
  in (id1, id2, id3, id4, id5, id6, id7, id8)

    );

UNION ALL 似乎更简单:

select dpd.objectid as id,
from mvdynamicprotectivedevice dpd
where dpd.fema_wo = 'WBS.F.81109.1.1.2'
union all
select ss.objectid
from mvsupportstructure ss join
     mvdynamicprotectivedevice dpd
     on dpd.fema_wo = ss.fema_wo and dpd.fema_wo = 'WBS.F.81109.1.1.2'
union all
select ohp.objectid
from mvoverheadprimaryline ohp join
     mvdynamicprotectivedevice dpd
     on dpd.fema_wo = ohp.fema_wo and dpd.fema_wo = 'WBS.F.81109.1.1.2'
. . . ;

我的猜测是,由于每个 table.

中的多个匹配项,您的外部联接显着增加了行数