`

Oracle 各种注释

阅读更多
       
为SQL语句添加注释:

http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/comments.htm#sthref2572
http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements006.htm#i31713
单行注释 用 --comment text
多行注释 用 /* comment txt */




使用 COMMENT ON ..IS 'text'语句为表、列、视图等添加注释:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_4009.htm#i2119719

http://www.adp-gmbh.ch/ora/sql/comment.html
comment on table  some_table       is 'some hopefully meaningful comment for some_table';
comment on table  some_view        is 'Views can also be commented, yet the statement is still: comment on table';
comment on column some_table.col_1 is 'Be sure to really give some meaningful comment';
comment on column some_view.col_1  is 'Useless, or wrong comments, are worse than no comment at all';





为PL/SQL的输出结果添加注释:
http://stackoverflow.com/questions/193107/print-text-in-oracle-sql-developer-sql-worksheet-window
将PL/SQL语句也输出到其执行后的输出结果中,方便对输出结果的查看,不至于混乱。方法很多:
1 使用 SET ECHO ON
引用
set echo on
select distinct deptno from dept;
select distinct deptno from emp; 
执行后的输出:
引用
SQL> select distinct deptno from dept

    DEPTNO
----------
        10
        20
        30
        40

4 rows selected.
SQL> select distinct deptno from emp

    DEPTNO
----------
        30
        20
        10

3 rows selected.

2 使用REM(remark)(前提是得SET ECHO ON)
引用
set echo on
REM CommentFor Dept Select
select distinct deptno from dept;
select distinct deptno from emp;  
执行后的输出:
引用
SQL> REM CommentFor Dept Select
SQL> select distinct deptno from dept

    DEPTNO
----------
        10
        20
        30
        40

4 rows selected.
SQL> select distinct deptno from emp

    DEPTNO
----------
        30
        20
        10

3 rows selected.

3 结合使用 SET SERVEROUTPUT ON和存储过程输出函数DBMS_OUTPUT.put_line
引用
SET SERVEROUTPUT ON
execute DBMS_OUTPUT.put_line('Dept Comment');
select distinct deptno from dept;
execute DBMS_OUTPUT.put_line('Emp Comment');
select distinct deptno from emp;
执行后的输出:
引用
Dept Comment
PL/SQL procedure successfully completed.

    DEPTNO
----------
        10
        20
        30
        40

4 rows selected.
Emp Comment
PL/SQL procedure successfully completed.

    DEPTNO
----------
        30
        20
        10

3 rows selected.

4 使用 PROMPT
引用
PROMPT Dept Comment
select distinct deptno from dept;
PROMPT Emp Comment
select distinct deptno from emp; 
执行后的输出:
引用
Dept Comment

    DEPTNO
----------
        10
        20
        30
        40

4 rows selected.
Emp Comment

    DEPTNO
----------
        30
        20
        10

3 rows selected.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics