ITPub博客

首页 > 数据库 > Oracle > [20201218]dbms_output.put_line无法输出前面的空格.txt

[20201218]dbms_output.put_line无法输出前面的空格.txt

原创 Oracle 作者:lfree 时间:2020-12-18 09:35:32 0 删除 编辑

[20201218]dbms_output.put_line无法输出前面的空格.txt

--//昨天别人问的问题,自己测试看看。

1.环境:
SCOTT@book> @ 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

2.测试:
SCOTT@book> @ desc_proc sys dbms_output put_line
INPUT OWNER PACKAGE_NAME OBJECT_NAME
sample : @desc_proc sys dbms_stats gather_%_stats
OWNER      PACKAGE_NAME         OBJECT_NAME                      SEQUENCE ARGUMENT_NAME        DATA_TYPE            IN_OUT    DEFAULTED
---------- -------------------- ------------------------------ ---------- -------------------- -------------------- --------- ----------
SYS        DBMS_OUTPUT          PUT_LINE                                1 A                    VARCHAR2             IN        N

SCOTT@book> set serveroutput on
SCOTT@book> exec dbms_output.put_line ('   this is a test');
this is a test
PL/SQL procedure successfully completed.

--//感觉输入参数做了处理。

SCOTT@book> exec dbms_output.put_line (chr(32)||chr(32)||'   this is a test');
this is a test

PL/SQL procedure successfully completed.
--//^_^依旧。

3.上网检索发现:
https://stackoverflow.com/questions/2584492/how-to-prevent-dbms-output-put-line-from-trimming-leading-whitespace

--//链接给出几种解决方法:
SCOTT@book> set serveroutput on
SCOTT@book> show serveroutput
serveroutput ON SIZE UNLIMITED FORMAT WORD_WRAPPED
--//实际上缺省是WORD_WRAPPED。
SCOTT@book> exec dbms_output.put_line(lpad('this', 8, ' ')||' is a test');
this is a test
PL/SQL procedure successfully completed.
--//这样跟我前面测试一样不行。

SCOTT@book> SET SERVEROUTPUT ON FORMAT WRAPPED
SCOTT@book> exec dbms_output.put_line (chr(32)||chr(32)||'   this is a test');
     this is a test

PL/SQL procedure successfully completed.

SCOTT@book> SET SERVEROUTPUT ON FORMAT TRUNCATED
SCOTT@book> exec dbms_output.put_line (chr(32)||chr(32)||'   this is a test');
     this is a test
PL/SQL procedure successfully completed.

--//最后,注意完成要选择关闭,不要显示查看执行计划出现问题。
SCOTT@book> set serveroutput on
SCOTT@book> select * from dept where rownum=1;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK

SCOTT@book> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------
SQL_ID  9babjv8yq8ru3, child number 0
BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;
NOTE: cannot fetch plan for SQL_ID: 9babjv8yq8ru3, CHILD_NUMBER: 0
      Please verify value of SQL_ID and CHILD_NUMBER;
      It could also be that the plan is no longer in cursor cache (check v$sql_plan)
8 rows selected.

SCOTT@book> set serveroutput off

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

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

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969275