Ny difference between Rem and — comments for SQL*Plus

oracleoracle-11gsqlplus

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?

Best Answer

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.