错误 - 关键字没有找到预期
我试图创建一个使用在Oracle 10g中,我收到以下错误每次下面的代码和一个表:错误 - 关键字没有找到预期
ORA-00923: FROM keyword not found where expected
查询如下:
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。但是这个代码中的错误是什么?
回答:
尝试
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)
回答:
你有列别名问题 尝试用双引号“”像这样
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
回答:
问题是无效的别名,所以使用双引号来克服问题
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
回答:
在您的别名上使用引号。
Create table Tab2 nologging AS SELECT 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
以上是 错误 - 关键字没有找到预期 的全部内容, 来源链接: utcz.com/qa/257984.html