Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

On SQL*Plus prompt, both Rem and -- qualify as comment indicators:

Rem this is a comment
-- this is also a comment
create table emp (
id number primary key,
name cvarchar2(40));

Is there any difference at all between the two commenting techniques?

share|improve this question
1  
And don't forget /* comment */ is valid too. –  Gaius Jan 23 '11 at 21:44

3 Answers 3

up vote 10 down vote accepted

The difference is that -- and /* */ can be used in a PL/SQL block, while REM[ARK] cannot. The following will work in SQL*Plus:

REM comment
-- comment
/* comment */
begin
   DBMS_OUTPUT.PUT_LINE('Test'); --comment
   DBMS_OUTPUT.PUT_LINE('Test'); /* comment */
end; 
/

These will not:

begin
   DBMS_OUTPUT.PUT_LINE('Test'); REM comment
end; 
/

begin
   REM comment
   DBMS_OUTPUT.PUT_LINE('Test');
end; 
/

The 11.2 documentation on all comment types has more comment information. The basics are...

You can enter comments in a script in three ways:

  • using the SQL*Plus REMARK command for single line comments.

  • using the SQL comment delimiters /*... */ for single or multi-line comments.

  • using ANSI/ISO (American National Standards Institute/International Standards Organization) comments - - for single line comments.

The documentation also includes notes on four places that comments should not be used, but these do not include any further differences.

share|improve this answer
    
To be fair, I've never encountered a language that supports REM as a comment delimiter where those three letters aren't the first command characters on a given line (cf @REM in batch files) –  jcolebrand Jan 24 '11 at 22:05
    
@jcolebrand Indeed. –  Leigh Riffel Jan 25 '11 at 3:20

REM is supported due to being the way MS BATCH files are commented, and this tool being used with automation environments.

-- is supported due to being part of the SQL standard. ( http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt page 83 cf <comment introducer> ::= <minus sign><minus sign>[<minus sign>...] )

share|improve this answer

No there should be no difference at all.

share|improve this answer
1  
Why two comment styles then? –  Lazer Jan 23 '11 at 21:37
    
@Lazer: backwards compatibility I expect –  Gaius Jan 23 '11 at 21:45
    
I believe that REM is valid only for the tool SQLPlus, while -- and /**/ are coming from the language, they work also in MS SQL - TSQL for example. –  Marian Jan 23 '11 at 21:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.