oracle-databaseoracle-sqldevelopercommentsunion-all

Oracle SQL Developer claims missing select just because of end line comment


If I select all text in the SQL Developer and execute it, it works:

select 16 cc, date '2025-03-05' coDate, 18 nr, 594.34 tvaInc, 1 cat from dual union all
select 16 cc, date '2025-03-06' coDate, 22 nr, 356.44 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-07' coDate, 41 nr, 677.92 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-08' coDate, 26 nr, 409.67 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-10' coDate, 93 nr, 729.66 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-11' coDate, 89 nr, 762.13 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-11' coDate, 169 nr, 684.21 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-15' coDate, 29 nr, 797.18 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-20' coDate, 26 nr, 921.89 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-20' coDate, 304 nr, 140.01 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-21' coDate, 23 nr, 786.96 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-22' coDate, 16 nr, 667.75 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-24' coDate, 17 nr, 22.56 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-24' coDate, 278 nr, 1089.98 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-26' coDate, 21 nr, 562.33 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-27' coDate, 26 nr, 2057.79 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-29' coDate, 47 nr, 988.11 tvaInc, 1 cat from dual union all  --
select 16 cc, date '2025-03-31' coDate, 263 nr, 109.06 tvaInc, 1 cat from dual

But if I add and empty end-line-comment with two dashes in first line like this:

select 16 cc, date '2025-03-05' coDate, 18 nr, 594.34 tvaInc, 1 cat from dual union all --
select 16 cc, date '2025-03-06' coDate, 22 nr, 356.44 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-07' coDate, 41 nr, 677.92 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-08' coDate, 26 nr, 409.67 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-10' coDate, 93 nr, 729.66 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-11' coDate, 89 nr, 762.13 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-11' coDate, 169 nr, 684.21 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-15' coDate, 29 nr, 797.18 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-20' coDate, 26 nr, 921.89 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-20' coDate, 304 nr, 140.01 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-21' coDate, 23 nr, 786.96 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-22' coDate, 16 nr, 667.75 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-24' coDate, 17 nr, 22.56 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-24' coDate, 278 nr, 1089.98 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-26' coDate, 21 nr, 562.33 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-27' coDate, 26 nr, 2057.79 tvaInc, 1 cat from dual union all  
select 16 cc, date '2025-03-29' coDate, 47 nr, 988.11 tvaInc, 1 cat from dual union all  --
select 16 cc, date '2025-03-31' coDate, 263 nr, 109.06 tvaInc, 1 cat from dual

it claims:

ORA-00928: Schlüsselwort SELECT fehlt
00928. 00000 -  "missing SELECT keyword"
*Cause:    
*Action:
Fehler in Zeile: 1 Spalte: 93

SQL Developer 23.1.0.097 Build 097.1607, Oracle DB version 19.15.0.0.0.

Is this an SQL Developer/Oracle error?

PS: As a workaround I can use /* ... */ comments.


Solution

  • It seems SQL Developer (and SQL*Plus, and SQLcl) is treating the second dash as the line continuation character:

    You can continue a long SQL*Plus command by typing a hyphen at the end of the line and pressing Return. If you wish, you can type a space before typing the hyphen.

    If you run your second statement as a script, or in SQL*Plus or SQLcl, it shows that the lines have been combined:

    select ... from dual union all - select ...from dual union all  
    

    .. with a single dash. The second dash has been 'consumed' as the continuation character and the lines have then been concatenated together. The single remaining dash then makes the resulting statement invalid by the time it reaches the database to be parsed.

    It only appears to consider a dash as a continuation character on any line if there is one on the first line - so in your first statement it doesn't try to concatenate the last two lines together, so that doesn't lose a dash and doesn't error. But if you add -- at the end of every line you can see it concatenate all of them together, with single dashes.

    It's possibly (probably?) a bug that it doesn't ignore a double dash and treat that as a comment, but there doesn't seem to be much point ending a line in just --. If you actually have a comment, with any text (but not just whitespace) after the -- then that is still treated as a comment, and again the query works.