HiveBrain v1.2.0
Get Started
← Back to all entries
gotchaMajor

Is there any difference between Rem and -- comments for SQL*Plus?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
remsqlanydifferenceplusbetweenforandtherecomments

Problem

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?

Solution

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.

Code Snippets

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

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

Context

StackExchange Database Administrators Q#811, answer score: 21

Revisions (0)

No revisions yet.