我正在尝试使用oracle 10g中的以下代码创建一个表,每次我收到以下错误:
ORA-00923:未找到FROM关键字
查询如下:
Create table Tab2 nologging as
select /*+parallel(a,6)*/ Tab1col1, Tab1col2,
MAX(case when tab1Col5 = '21-aug-2015' then Tab1Col3 end) 21AUGBALANCE,
MAX(case when tab1Col5 = '22-aug-2015' then Tab1Col3 end) 22AUGBALANCE,
MAX(case when tab1Col5 = '23-aug-2015' then Tab1Col3 end) 23AUGBALANCE
from Tab1 a
GROUP BY msisdn, sdp_node
order by msisdn, sdp_node
表1有5列,即tab1Col1, tab1Col2, Tab1Col3, Tab1Col4 and Tab1Col5.
我需要从Tab1创建Tab2,它还有5列1,2,3,4,5。但是这段代码中的错误是什么?
答案 0 :(得分:1)
试
Create table Tab2 nologging as
select /*+parallel(a,6)*/ Tab1col1, Tab1col2,
MAX(case when tab1Col5 = '21-aug-2015' then Tab1Col3 end) "21AUGBALANCE",
MAX(case when tab1Col5 = '22-aug-2015' then Tab1Col3 end) "22AUGBALANCE",
MAX(case when tab1Col5 = '23-aug-2015' then Tab1Col3 end) "23AUGBALANCE"
from Tab1 a
GROUP BY msisdn, sdp_node
order by msisdn, sdp_node
oracle支持以数字开头的列名,但是如果你想要一个以数字开头的列名,你必须引用它们。
或者,选择不同的名字(例如BALANCE21AUG)
答案 1 :(得分:1)
列别名有问题 尝试使用双引号“”像这样
Create table Tab2 nologging as
select /*+parallel(a,6)*/ Tab1col1, Tab1col2,
MAX(case when tab1Col5 = '21-aug-2015' then Tab1Col3 end) "21AUGBALANCE",
MAX(case when tab1Col5 = '22-aug-2015' then Tab1Col3 end) "22AUGBALANCE",
MAX(case when tab1Col5 = '23-aug-2015' then Tab1Col3 end) "23AUGBALANCE"
from Tab1 a
GROUP BY msisdn, sdp_node
order by msisdn, sdp_node
答案 2 :(得分:1)
问题是无效别名,因此请使用双引号来解决问题
Create table Tab2 nologging as
select /*+parallel(a,6)*/ Tab1col1, Tab1col2,
MAX(case when tab1Col5 = '21-aug-2015' then Tab1Col3 end) as "21AUGBALANCE",
MAX(case when tab1Col5 = '22-aug-2015' then Tab1Col3 end) as "22AUGBALANCE",
MAX(case when tab1Col5 = '23-aug-2015' then Tab1Col3 end) as "23AUGBALANCE"
from Tab1 a
GROUP BY msisdn, sdp_node
order by msisdn, sdp_node