Problem
I lately ran into problems that a select returned an unexpected negative results und certain condions, e.g. I expected 1 but it returned -1.
select --
1
from dual;
Reason
It turns out that this is a behaviour seen only in clients using SQLPlus or the same libraries as SQLPlus or something of the sort. From https://docs.oracle.com/en/database/oracle/oracle-database/19/sqpug/REMARK.html
A "–" at the end of a REMARK line is treated as a line continuation character.
To me, this is a flaw in the SQLPlus design as, to the best of my knowledge, the SQL standard does not inhibt empty line comments or defines a line continuation character (like \ in bash, if after \ there immediately follows line break). It is even worse as it does not work consistently this way. The following should, if - is line continuation character, throw a syntax error at both instances of the -- but works perfectly fine.
--
select 1
from --
dual;
Solution
Do not use empty line comments. Place at least one none whitespace character behind the --.
Keine Kommentare:
Kommentar veröffentlichen