缺少关键字ORA00905

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了缺少关键字ORA00905相关的知识,希望对你有一定的参考价值。

你好,你可以帮我吗?我得到错误缺少关键字。见下面的代码。提前致谢。

SELECT Datum, Wdomain, Lgstkproc, Username,
Case when LGSTKPROC = 'NAVUL'
         COUNT (unique username '-'palnumber end nr_pal_per_user_navul,
Case when LGSTKPROC !=‘NAVUL’
         COUNT (unique username '-'palnumber end nr_pal_per_user_veplaatst
From (
SELECT USERNAME, RES, RESTYPE, WDOMAIN, LGSTKPROC,  LOCNAME, ENDLOCNAME, PALNUMBER, TRUNC(SYSDATE-1) datum 
FROM TransportStock$VW TS
WHERE TRUNC(timestamp)<TRUNC(sysdate)-1
AND res NOT LIKE '%CONVS%'
)
Group by Username, Datum,  Lgstkproc, Wdomain
答案

你错过了一个逗号,这里:

SELECT datum,
       wdomain,
       lgstkproc,
       username,
       COUNT (DISTINCT CASE WHEN lgstkproc = 'NAVUL' THEN 
                                 username || '-' || palnumber
                       END) AS nr_pal_per_user_navul,                --> comma missing here
       COUNT (DISTINCT CASE WHEN lgstkproc != 'NAVUL' THEN 
                                 username || '-' || palnumber
                       END) AS nr_pal_per_user_veplaatst
FROM (SELECT username,
             res,
             restype,
             wdomain,
             lgstkproc,
             locname,
             endlocname,
             palnumber,
             trunc(SYSDATE - 1) datum
      FROM transportstock$vw ts
      WHERE trunc(timestamp) < trunc(SYSDATE) - 1
        AND res NOT LIKE '%CONVS%'
     )
GROUP BY username,
         datum,
         lgstkproc,
         wdomain

如果正确格式化您编写的代码,事情会更加清晰。

此外,那些COUNTs没有多大意义 - 无论CASE的价值如何,lgstkprocs都选择相同的值。

另一答案

这没有意义:

Case when LGSTKPROC = 'NAVUL'
     COUNT (unique username '-'palnumber end nr_pal_per_user_navul,

我推测你想要:

count(distinct case when LGSTKPROC = 'NAVUL'
                    then username || '-' || palnumber
               end) as nr_pal_per_user_navul
另一答案

我非常感谢任何额外的帮助,根据戈登的建议我改变了几行,现在收到错误“找不到关键字的关键字”

选择基准,Wdomain,Lgstkproc,用户名,计数(当LGSTKPROC ='NAVUL'然后用户名||' - '|| palnumber结束时的不同情况)作为nr_pal_per_user_navul计数(当LGSTKPROC!='NAVUL'然后用户名||'时的不同情况 - '|| palnumber end)为nr_pal_per_user_veplaatst

           From (
           SELECT USERNAME, RES, RESTYPE, WDOMAIN, LGSTKPROC,  LOCNAME, ENDLOCNAME, PALNUMBER, TRUNC(SYSDATE-1) datum 
           FROM TransportStock$VW TS
           WHERE TRUNC(timestamp)<TRUNC(sysdate)-1
           AND res NOT LIKE '%CONVS%'
           )
           Group by Username, Datum,  Lgstkproc, Wdomain

以上是关于缺少关键字ORA00905的主要内容,如果未能解决你的问题,请参考以下文章

ORA-00905: TOAD 中缺少关键字

缺少关键字ORA00905

ORA-00905: 缺少关键字错误 oracle

ORA-00905: 缺少关键字

ORA-00905: 缺少关键字 Hibernate 查询

ORA-00905: 缺少关键字(约束外键)