Boa tarde a todos,
Fiz um teste no PL/SQL DEVELOPER e não dá erro, mas quando coloco o script no SQL do Scriptcase da erro, ele esta misturando o CASE.
meu SQL é assim.
SELECT codigo,
cod,
nome,
nasc,
trunc((months_between(sysdate, (NASC)))/12) as idade,
sexo,
(CASE WHEN emp = 0 THEN ‘F’ WHEN emp = -1 THEN ‘J’ END) as Pessoa,
(CASE WHEN cod = 0 THEN ‘T’ ELSE ‘D’ END) as benef,
(CASE
WHEN (trunc(months_between(sysdate, (NASC))/12) >= 0) AND (trunc(months_between(sysdate, (NASC))/12) <=18) THEN ’ 0 a 18’
WHEN (trunc(months_between(sysdate, (NASC))/12) >= 19) AND (trunc(months_between(sysdate, (NASC))/12) <=23) THEN ‘19 a 23’
WHEN (trunc(months_between(sysdate, (NASC))/12) >= 24) AND (trunc(months_between(sysdate, (NASC))/12) <=28) THEN ‘24 a 28’
WHEN (trunc(months_between(sysdate, (NASC))/12) >= 29) AND (trunc(months_between(sysdate, (NASC))/12) <=33) THEN ‘29 a 33’
WHEN (trunc(months_between(sysdate, (NASC))/12) >= 34) AND (trunc(months_between(sysdate, (NASC))/12) <=38) THEN ‘34 a 38’
WHEN (trunc(months_between(sysdate, (NASC))/12) >= 39) AND (trunc(months_between(sysdate, (NASC))/12) <=43) THEN ‘39 a 43’
WHEN (trunc(months_between(sysdate, (NASC))/12) >= 44) AND (trunc(months_between(sysdate, (NASC))/12) <=48) THEN ‘44 a 48’
WHEN (trunc(months_between(sysdate, (NASC))/12) >= 49) AND (trunc(months_between(sysdate, (NASC))/12) <=53) THEN ‘49 a 53’
WHEN (trunc(months_between(sysdate, (NASC))/12) >= 54) AND (trunc(months_between(sysdate, (NASC))/12) <=58) THEN ‘54 a 58’
WHEN (trunc(months_between(sysdate, (NASC))/12) >= 59) THEN ‘59 ou Mais’
END) as faixa_etaria
FROM cadastro
o erro que aparece quando executo é esse.
ERRO
Erro ao acessar o banco de dados
ORA-00905: palavra-chave não encontrada
SelectLimit(SELECT codigo, cod, nome, nasc, sexo, CASE WHEN (trunc((months_between(sysdate,(NASC)))/12) >= 0 AND trunc((months_between(sysdate,(NASC)))/12) <=18) THEN ’ 0 a 18’ WHEN (trunc((months_between(sysdate,(NASC)))/12) >= 19 AND trunc((months_between(sysdate,(NASC)))/12) <=23) THEN ‘19 a 23’ WHEN (trunc((months_between(sysdate,(NASC)))/12) >= 24 AND trunc((months_between(sysdate,(NASC)))/12) <=28) THEN ‘24 a 28’ WHEN (trunc((months_between(sysdate,(NASC)))/12) >= 29 AND trunc((months_between(sysdate,(NASC)))/12) <=33) THEN ‘29 a 33’ WHEN (trunc((months_between(sysdate,(NASC)))/12) >= 34 AND trunc((months_between(sysdate,(NASC)))/12) <=38) THEN ‘34 a 38’ WHEN (trunc((months_between(sysdate,(NASC)))/12) >= 39 AND trunc((months_between(sysdate,(NASC)))/12) <=43) THEN ‘39 a 43’ WHEN (trunc((months_between(sysdate,(NASC)))/12) >= 44 AND trunc((months_between(sysdate,(NASC)))/12) <=48) THEN 'Juridica’0 WHEN (trunc((months_between(sysdate,(NASC)))/12) >= 49 AND trunc((months_between(sysdate,(NASC)))/12) <=53) THEN 'Juridica’1 WHEN (trunc((months_between(sysdate,(NASC)))/12) >= 54 AND trunc((months_between(sysdate,(NASC)))/12) <=58) THEN 'Juridica’2 WHEN (trunc((months_between(sysdate,(NASC)))/12) >= 59) THEN 'Juridica’3 END as faixa_etaria, trunc((months_between(sysdate,(NASC)))/12) as idade, (CASE WHEN emp = 0 THEN ‘Fisica’ WHEN emp = -1 THEN ‘Juridica’ END) as pessoa, (CASE WHEN cod = 0 THEN ‘Titular’ ELSE ‘Dependente’ END) as benef from cadastro, 12, 0)
Percebi que ele esta misturando no final …
trunc((months_between(sysdate,(NASC)))/12) <=58) THEN 'Juridica’2 WHEN (trunc((months_between(sysdate,(NASC)))/12) >= 59) THEN 'Juridica’3 END as faixa_etaria, trunc((months_between(sysdate,(NASC)))/12) as idade, (CASE WHEN emp = 0 THEN ‘Fisica’ WHEN emp = -1 THEN ‘Juridica’ END) as pessoa, (CASE WHEN cod = 0 THEN ‘Titular’ ELSE ‘Dependente’ END) as benef from cadastro, 12, 0)
O que pode ser?
Grato,
Ilton