SQL*Plus 的 Rem 和 -- 注释之间有什么区别吗?

Laz*_*zer 15 oracle oracle-11g sqlplus

在 SQL*Plus 提示符下,Rem和 都--可以作为注释指示符:

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

这两种评论技术有什么区别吗?

Lei*_*fel 21

区别在于--/* */可以在 PL/SQL 块中使用,而REM[ARK]不能。以下将在 SQL*Plus 中工作:

REM comment
-- comment
/* comment */
begin
   DBMS_OUTPUT.PUT_LINE('Test'); --comment
   DBMS_OUTPUT.PUT_LINE('Test'); /* comment */
end; 
/
Run Code Online (Sandbox Code Playgroud)

这些不会:

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

begin
   REM comment
   DBMS_OUTPUT.PUT_LINE('Test');
end; 
/
Run Code Online (Sandbox Code Playgroud)

所有评论类型11.2 文档都有更多评论信息。基本原理是...

您可以通过三种方式在脚本中输入注释:

  • 对单行注释使用 SQL*Plus REMARK 命令。

  • 将 SQL 注释分隔符 /*... */ 用于单行或多行注释。

  • 使用 ANSI/ISO(美国国家标准协会/国际标准组织)注释 - - 用于单行注释。

该文档还包括关于不应使用注释的四个地方的说明,但这些不包括任何进一步的差异。