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

来源:这里教程网 时间:2026-03-03 16:17:31 作者:

[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

相关推荐