【问题标题】:Prevent output of SPOOL from being wrapped防止 SPOOL 的输出被包装
【发布时间】:2014-09-28 08:28:07
【问题描述】:

我正在尝试使用 SQLPLUS 中的 SPOOL 命令为数据库中的对象生成所有 DDL:

SET trimspool ON
SET wrap off
SET heading off
SET linesize 300
SET echo off
SET pages 999
SET long 90000
Col object_type format a10000
Col object_name format a10000
Col owner format a10000

spool export.out

SELECT DBMS_METADATA.GET_DDL(object_type, object_name, owner)
FROM all_OBJECTS 
WHERE OWNER = 'DMALM' 
and object_type not like '%PARTITION'
and object_type not like '%BODY'
and object_type not like '%LOB';

spool off
quit

但是我得到的输出文件在第 80 列被剪切。 如何防止输出文件被包装?

【问题讨论】:

  • 您确定文件中的数据是包装的,而不是您的文本编辑器包装的吗?
  • @AlexPoole 我正在使用记事本++打开文件并关闭了换行选项..
  • 您将 linesize 保持为 300 字节,但将 object_type、object_name、owner 的长度保持为一万(即 a10000)。将它们设置为 a30,因为它们都不能比这更大......另外,您需要使用 DBMS_METADATA.SET_TRANSFORM_PARAM 来设置各种参数,以便您的输出符合要求的格式。
  • 那些col 设置无关紧要,因为这些列不包含在结果集中。

标签: oracle sqlplus spool


【解决方案1】:

你还需要这样做:

SET longchunksize 90000

作为the documentation says:

数据类型列的默认宽度是数据库中列的宽度。 LONGBLOBBFILECLOBNCLOBXMLType 的列宽默认为 SET LONGCHUNKSIZESET LONG 中的较小值。

您已经设置了LONG,但LONGCHUNKSIZE 仍为其默认值80,因此您需要增加该值以匹配。您可以使用show all 查看所有当前设置。

这会保留换行符和缩进applied by default

【讨论】:

    【解决方案2】:

    听起来你可能想试试:

    set longchunksize 100
    

    或等价物。试验一下这个数字,看看是否有帮助。

    来源Oracle Docs

    【讨论】:

      【解决方案3】:

      使用 word_wrapped 怎么样?

      SET trimspool ON
      SET heading off
      SET linesize 300
      SET echo off
      SET pages 999
      SET long 90000
      set termout off
      column txt format a121 word_wrapped
      Col object_type format a10000
      Col object_name format a10000
      Col owner format a10000
      spool export.out
      
      SELECT DBMS_METADATA.GET_DDL(object_type, object_name, owner)txt
      FROM all_OBJECTS 
      WHERE OWNER = 'DMALM' 
      and object_type not like '%PARTITION'
      and object_type not like '%BODY'
      and object_type not like '%LOB';
      
      spool off
      quit
      

      【讨论】:

      • 这可行,但会丢失默认应用的缩进(在 DBMS_METADATA 转换参数中打开了“漂亮”)。
      猜你喜欢
      • 2015-06-06
      • 2021-12-13
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      • 2022-08-16
      • 1970-01-01
      • 1970-01-01
      • 2012-07-17
      相关资源
      最近更新 更多