错误 - 在预期位置找不到关键字

Error - Keyword not found where expected

我试图在 oracle 10g 中使用以下代码创建 table,但每次我都收到以下错误:

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

Table 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