1

sqlcl 在格式化缓冲区时似乎使用格式化规则,但在格式化文件时忽略它们。

我有一个输入文件(test.sql)和一小组格式化规则(format.xml)

[abayley@abayley1 ~]$ cat test.sql
SELECT * from DUAL;

[abayley@abayley1 ~]$ cat format.xml
<options>
<useTab>false</useTab>
<idCase>oracle.dbtools.app.Format.Case.lower</idCase>
<kwCase>oracle.dbtools.app.Format.Case.lower</kwCase>
</options>

显示应用于缓冲区而不是文件的规则的 sqlcl 会话:

[abayley@abayley1 ~]$ sql username/password@server.fqdn:1521/dbname

SQLcl: Release 20.2 Production on Tue Aug 25 07:43:00 2020

Copyright (c) 1982, 2020, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c Standard Edition Release 12.2.0.1.0 - 64bit Production

SQL> @test.sql

   DUMMY
________
X

SQL> format rules format.xml
Formatter rules loaded
SQL> format buffer
  1  select
  2      *
  3  from
  4*     dual;
SQL> format file test.sql test2.sql
SQL>
Disconnected from Oracle Database 12c Standard Edition Release 12.2.0.1.0 - 64bit Production

[abayley@abayley1 ~]$ cat test2.sql
SELECT
    *
FROM
    dual;
[abayley@abayley1 ~]$

设置 SQLFORMATPATH 也不起作用:

[abayley@abayley1 ~]$ export SQLFORMATPATH=format.xml
[abayley@abayley1 ~]$ sql username/password@server.fqdn:1521/dbname

SQLcl: Release 20.2 Production on Tue Aug 25 08:06:26 2020

Copyright (c) 1982, 2020, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c Standard Edition Release 12.2.0.1.0 - 64bit Production

SQL> SELECT * from DUAL;

   DUMMY
________
X

SQL> format buffer
  1  SELECT
  2      *
  3  FROM
  4*     dual;
SQL> exit
4

1 回答 1

0

将文件加载到缓冲区中,将其格式化并保存回来可能是一种解决方法:

  format rules format.xml
  get test.sql nolist
  format buffer
  save test.sql replace
于 2021-06-30T20:54:46.997 回答