Oracle SQL Developer treats my comment as a command

17,288

Solution 1

This seems like a SQL Developer bug/feature.


desc[ribe] is one of the SQL*Plus statements that are supported by the SQL Worksheet.

https://docs.oracle.com/cd/E11882_01/doc.112/e12152/intro.htm#RPTUG10710


In SQL Developer we can notice some interesting phenomenons that do not exist in SQL*Plus:
1. when given multiple tokens, all token are being ignored except for the last one.

desc some gibberish - yada yada yada t3

Name Null Type       
---- ---- ---------- 
C3        NUMBER(38) 

2. -- is not being treated as a notation for line comment, but as an object name.

desc --

ERROR:                          
------------------------------- 
ERROR: object -- does not exist 

3. A single semicolon is being ignored and not being treated as a statement terminator.

desc ; ; ; ; ; ; t1;

Name Null Type       
---- ---- ---------- 
C1        NUMBER(38) 

Therefore, when given the command -

DESC Students; -- Some comment

Only the last token 'comment' is being handled and yields an error, since there is no object 'comment'.

Solution 2

-- and \* *\ and REM are all OK in SQL*Plus scripts, but there are several restrictions. https://docs.oracle.com/cd/B10501_01/server.920/a90842/ch6.htm#1006369

You ran into the issue discussed in the second paragraph - do not add comments after statement terminators.

Share:
17,288
argamanza
Author by

argamanza

Updated on June 23, 2022

Comments

  • argamanza
    argamanza almost 2 years

    I've created some very basic SQL script:

    /*
      Change date format
    */
    alter session set nls_date_format='DD/MM/YYYY';
    
    /*
      Drop old tables (if exists)
    */
    DROP TABLE Students;
    
    /*
      Create new tables
    */
    CREATE TABLE Students
      (
        Id NUMBER(6) PRIMARY KEY,
        LastName VARCHAR2(20),
        FirstName VARCHAR2(10),
        Address VARCHAR2(10),
        BirthDay DATE,
        GroupId NUMBER(3)
      );
    
    /*
      Check the table was created successfully
    */
    DESC Students;
    
    /*
      Insert a new record to the table
    */
    INSERT INTO Students VALUES(101, 'Solin', 'Dan', 'Beer-Sheva', '01/02/1985', 11);
    
    /*
      Check the record was inserted succesfully
    */
    SELECT * FROM Students;
    
    /*
      Add 'AvgMark' field to the table with default of 0
    */
    ALTER TABLE Students ADD AvgMark NUMBER(5,2) DEFAULT 0;
    
    /*
      Check that the new field was added
    */
    DESC Students; 
    
    /*
      Insert 3 new records to the table
    */
    INSERT INTO Students VALUES(102, 'Tal', 'Ruti', 'Tel-Aviv', '10/07/1988', 12, 70);
    INSERT INTO Students VALUES(103, 'Kohen', 'Yossi', 'Dimona', '01/08/1987', 11, 80);
    INSERT INTO Students VALUES(104, 'Toys', 'Vered', 'Tel-Aviv', '15/09/1988', 12, 90);
    
    /*
      Check the records were inserted succesfully
    */
    SELECT * FROM Students;
    
    /*
      Change 'Address' data type to VARCHAR2(15)
    */
    ALTER TABLE Students MODIFY Address VARCHAR2(15);
    
    /*
      Check that the data type has changed
    */
    DESC Students; -- Some comment
    

    At the end of the Script Output i get this Error Message: ERROR: object COMMENT does not exist

    If i'll change the comment to Hello World i'll get the same error for WORLD "object"...

    I changed the whole script to avoid single line comments, and the result is the same.

    I could avoid it again in this example but i really want to understand what's causing this weird problem...


    Another thing which might help solving the issue, is another weird error i have in the same script, few lines above the comment. in this line: ALTER TABLE Students MODIFY Address VARCHAR2(15);

    SQL Developer shows me an error under the last two characters (the right parenthesis and the semicolon) saying Syntax error. Partially recognized rules (Railroad diagrams): ...

    If i'll run the statement it'll work just fine...

  • Alex Poole
    Alex Poole over 7 years
    I don't see that behaviour in 4.2; which version are you seeing it in, out of interest?
  • David דודו Markovitz
    David דודו Markovitz over 7 years
    @AlexPoole, 4.1.3.20