0

考虑下表:

在此处输入图像描述

我正在使用下面的查询(在SQL Server中)将此表转换为平面表,如下所示: 在此处输入图像描述

我想使用 Oracle SQL 做同样的事情。但是,该查询在“Oracle SQL”语言中不起作用:cross apply下面使用的,在 Oracle 中不起作用。知道如何使用 Oracle SQL 等效地编写它吗?谢谢!

select t.employee_id,
   t.employee_name,
   c.data,
   c.old,
   c.new
 from test_table t
 cross apply
 (
   select 'Address', Address_Old, Address_new union all
   select 'Income', cast(income_old as varchar(15)), cast(income_new as varchar(15))
 ) c (data, old, new)
4

1 回答 1

1

如果没有 CROSS APPLY 的能力,就不那么简洁了:

select t.employee_id,
t.employee_name,
c.data,
DECODE (c.data, 'Address', t.address_old, 'Income', t.income_old) AS old,
DECODE (c.data, 'Address', t.address_new, 'Income', t.income_new) AS new
from test_table t
cross join
(
  select 'Address' AS data
  from dual
  union all
  select 'Income'
  from dual
 ) c
于 2013-09-25T16:05:13.977 回答