ORA-00905: ошибка отсутствия ключевого слова

Я продолжаю получать эту надоедливую ошибку всякий раз, когда я пытаюсь использовать этот код:

 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

Такое ощущение, что что-то в коде не на месте, или я что-то забыл сделать/добавить. Любая помощь будет оценена по достоинству.


person JamesP    schedule 15.04.2014    source источник
comment
В какой строке сообщается об ошибке (после того, как вы изменили case gsh.gl_code только на case, как указано в ответах)? Вы уверены, что это из case, а не из предложения joins/where, которое вы не показали?   -  person Alex Poole    schedule 15.04.2014
comment
это на этой линии when cast(gl_code as int) >= 01 and cast(gl_code as int) <=13 Жаба всегда указывает на знак >= рядом с 01   -  person JamesP    schedule 15.04.2014


Ответы (2)


Конструкция CASE имеет два варианта синтаксиса:

CASE foo WHEN 1 THEN 'blah' END
CASE WHEN foo=1 THEN 'blah' END

Вы пытаетесь использовать оба одновременно:

case gsh.gl_code
when cast(gl_code as int) >= 01

Так должно быть:

  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
person Gaurav Soni    schedule 15.04.2014
comment
не работает. помогло бы, если бы я сказал, что изначально включил другие элементы в оператор select? Я обновлю код сейчас. - person JamesP; 15.04.2014
comment
Вероятно, полезно объяснить, почему необходимо удалить эту ссылку на столбец (путанное использование двух типов регистра). @JamesP - после удаления вы все равно получаете ту же ошибку? - person Alex Poole; 15.04.2014
comment
@JamesP - Гаурав прав, вы не можете использовать CASE таким образом. Серьезно. - person Álvaro González; 15.04.2014
comment
нет, я получаю другую ошибку: ORA-00923: FROM keyword not found where expected - person JamesP; 15.04.2014
comment
@JamesP - вы удалили только часть gsh.gl_code или строку с case gsh.gl_code, а также ключевое слово case? - person Alex Poole; 15.04.2014
comment
Я ответил в основном так же, поэтому я взял на себя смелость объединить свою информацию с вашим вопросом, чтобы избежать такого очевидного обмана. Надеюсь, ты не против. - person Álvaro González; 15.04.2014
comment
Вот это да. Не могу поверить, что упустил одну маленькую деталь. Это case изначально находится в середине оператора select, и я забыл поставить запятую после части end as. добавление этой отсутствующей запятой вместе с предложением Гаурава действительно решило мою проблему. - person JamesP; 15.04.2014

Вы можете попробовать использовать скобки, чтобы дать приоритет условиям AND/OR. Например:

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'

может поможет...

person Federico    schedule 15.04.2014