首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ORA-00905:缺少关键字错误

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

Stack Overflow用户
提问于 2014-04-15 08:28:58
回答 2查看 1.3K关注 0票数 0

每当我尝试以下代码时,我都会得到这个令人讨厌的错误:

代码语言:javascript
复制
 select 
    gam.acid,
        gam.foracid,
        gam.acct_name,
        gam.sol_id,
        sol.sol_desc,
        gam.gl_sub_head_code,
        case gsh.gl_code
             when cast(gl_code as int) >= 01 and cast(gl_code as int) <=13
                      or cast(gl_code as int) >= 15 and cast(gl_code as int) <=24 then 'A'
                 when cast(gl_code as int) >= 28 and cast(gl_code as int) <= 31
                     or cast(gl_code as int) >= 33 and cast(gl_code as int) <= 39
                     or cast(gl_code as int) = 41
                     or cast(gl_code as int) >= 43 and cast(gl_code as int) <= 48 then 'L'
                 when cast(gl_code as int) = 51
                     or cast(gl_code as int) = 53
                     or cast(gl_code as int) >= 55 and cast(gl_code as int) <= 57 then 'C'
                 when cast(gl_code as int) >= 61 and cast(gl_code as int) <= 70
                     or cast(gl_code as int) >= 72 and cast(gl_code as int) <= 81 then 'I'
                 when cast(gl_code as int) = 84 or cast(gl_code as int) = 85
                     or cast(gl_code as int) >= 87 and cast(gl_code as int) <= 94 then 'E'
                 when cast(gl_code as int) >= 97 and cast(gl_code as int) <= 99 then 'S'
                 else null
          end as gl_classification
    from tbaadm.gam

我觉得有些东西在代码中不合适,或者我忘了做/添加一些事情。任何帮助都将不胜感激。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-15 08:33:57

construct有两个替代语法:

代码语言:javascript
复制
CASE foo WHEN 1 THEN 'blah' END
CASE WHEN foo=1 THEN 'blah' END

你试图同时使用这两种方法:

代码语言:javascript
复制
case gsh.gl_code
when cast(gl_code as int) >= 01

它应该是:

代码语言:javascript
复制
  select case
         --gsh.gl_code  remove this 
            when cast(gl_code as int) >= 01 and cast(gl_code as int) <=13
                or cast(gl_code as int) >= 15 and cast(gl_code as int) <=24 then 'A'
            when cast(gl_code as int) >= 28 and cast(gl_code as int) <= 31
                or cast(gl_code as int) >= 33 and cast(gl_code as int) <= 39
                or cast(gl_code as int) = 41
                or cast(gl_code as int) >= 43 and cast(gl_code as int) <= 48 then 'L'
            when cast(gl_code as int) = 51
                or cast(gl_code as int) = 53
                or cast(gl_code as int) >= 55 and cast(gl_code as int) <= 57 then 'C'
            when cast(gl_code as int) >= 61 and cast(gl_code as int) <= 70
                or cast(gl_code as int) >= 72 and cast(gl_code as int) <= 81 then 'I'
            when cast(gl_code as int) = 84 or cast(gl_code as int) = 85
                or cast(gl_code as int) >= 87 and cast(gl_code as int) <= 94 then 'E'
            when cast(gl_code as int) >= 97 and cast(gl_code as int) <= 99 then 'S'
            else null
        end as gl_classification
   from tbaadm.gam
票数 3
EN

Stack Overflow用户

发布于 2014-04-15 08:37:44

您可以尝试使用括号对AND/OR条件赋予优先级。例如:

代码语言:javascript
复制
when (cast(gl_code as int) >= 01 and cast(gl_code as int) <=13)
    or (cast(gl_code as int) >= 15 and cast(gl_code as int) <=24) then 'A'

也许会有帮助..。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23078331

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档