ITPub博客

首页 > 数据库 > Oracle > [20180111]Oracle Bulk Collect and Limit2

[20180111]Oracle Bulk Collect and Limit2

原创 Oracle 作者:lfree 时间:2018-01-11 08:59:49 0 删除 编辑

[20180111]Oracle's Bulk Collect and Limit2.txt

--//昨天在测试时遇到一个的奇怪问题,链接http://blog.itpub.net/267265/viewspace-2149969/,执行
--//@ limit 9 时,重复输出了2次。主要是我的glogin配置文件里面包含如下:
set termout off
call dbms_output.enable(1e6);
set termout on

--//itpub论坛的提问:http://www.itpub.net/thread-2096243-1-1.html
--//缺省设置 set serverout off,而且dbms_output设置为disable,而我在配置文件中打开了即使是set serverout off的情况下。
--//通过一个例子说明问题:

1.环境:
SCOTT@book> @ &r/ver1

PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SCOTT@book> show serveroutput
serveroutput OFF

2.测试:

SCOTT@book> call dbms_output.enable(1e6);
Call completed.

SCOTT@book> exec DBMS_OUTPUT.put_line ('this is a first test!');
PL/SQL procedure successfully completed.

--//现在不显示是正常的。

SCOTT@book> set serverout on
SCOTT@book> exec DBMS_OUTPUT.put_line ('this is a second test!');
this is a first test!
this is a second test!
PL/SQL procedure successfully completed.

--//OK,现在把在缓存的第一行一起显示出来。出现了2行。再次执行就不会了。

SCOTT@book> exec DBMS_OUTPUT.put_line ('this is a second test!');
this is a second test!
PL/SQL procedure successfully completed.


3.回到我当时的出现的问题就很好理解了。
我现在set serverout off情况下执行
set serverout off
@limit 9
set serverout on
@limit 9

--//这样就出现2次显示,感觉重复显示了。主要问题我在set serverout off的情况下打开了dbms_output.enable(1e6)。
--//而这样设置源于去年的这个帖子:http://blog.itpub.net/267265/viewspace-2148591/=>[20171211]dbms_output无serveroutput on
--//这样看来没有想作者想像的这么复杂,只要随手调用1次exec DBMS_OUTPUT.put_line就ok了。

4.测试:
--//退出在登录:
SCOTT@book> exec dbms_output.enable(1e6);
PL/SQL procedure successfully completed.

SCOTT@book> exec dbms_output.put_line('first');
PL/SQL procedure successfully completed.

SCOTT@book> set serverout on
SCOTT@book> exec dbms_output.put_line(' ');
first

PL/SQL procedure successfully completed.

--//退出在登录:
SCOTT@book> exec dbms_output.enable(1e6);

PL/SQL procedure successfully completed.

SCOTT@book> @ limit 9
old  13:       FETCH get_emp_data BULK COLLECT INTO emp_c LIMIT &1;
new  13:       FETCH get_emp_data BULK COLLECT INTO emp_c LIMIT 9;
PL/SQL procedure successfully completed.

SCOTT@book> @ &r/output_print.sql
PL/SQL procedure successfully completed.
OUTPUT
---------------
7369SMITH800
7499ALLEN1600
7521WARD1250
7566JONES2975
7654MARTIN1250
7698BLAKE2850
7782CLARK2450
7788SCOTT3000
7839KING5000


10 rows selected.

--//这样的好处不用设置set serverout on就能显示。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2150028/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969672