ORA - 00935: missing expression

422 views Asked by At

This is my code:

select max(vhis_data.C0432_SAMPL_VALUE1_R), vhis_data.C0401_aid
from vhis_data, T0401_accounts
where vhis_data.C0401_aid = T0401_accounts.C0401_aid
and (
vhis_data.c0401_aid between 1179 and 1291 or
vhis_data.c0401_aid between 1382 and 1402 or
vhis_data.c0401_aid between 1462 and 1620 or

# and so on until...

vhis_data.c0401_aid between 5450 and 5485 or
vhis_data.c0401_aid between 5503 and 5495 or
)

(these numbers represent various points in the system)

The program displayed an error:

 vhis_data.c0401_aid between 1179 and 1291 or
*
 ERROR at line 5:
ORA-00936: missing expression

What I've noticed is that the first part of the error references the first line in the and ( ... ) part of my code. I have also noticed that there is an extra or on the last line of my code. I can take it out, but is this extra or the only reason that the whole and (...) part does not work? Or is there another reason that my code is not working?

(I guess a sub-question of mine, then, is, if there is a missing expression, where does the code stop executing properly?)

For example, here, the missing expression is potentially the last line (because it is expecting something after the "or"). However, the code does not even go through the first line of the and (...) part of the code.

I have combed the net for explanations dealing with the error ORA-00936: missing expression but have not found anything relevant enough to help me in this particular situation.

I welcome any criticism or advice you may have, and thank you so much in advance for any contributions that you give me!

2

There are 2 answers

0
Randy On

you should not end the whole thing with an or

 5495 or
)

this makes the entire parenthetical phrase invalid - everything in the ()... so thats why the line number is flagged up top.

3
D Stanley On

Could this extra or be the only reason that the whole and (...) part does not work?

It's the reason the whole query does not work.

A SQL query does not "execute" in order like a string of commands. The entire query is compiled, a plan built, and the plan executed. For that reason any syntax errors are often shown to point to lines that do not have the actual error.

So the "code" does not "execute" at all. The compilation fails, so there's nothing to execute.