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
将文件加载到缓冲区中,在那里格式化并保存回来可能是一种变通方法:
format rules format.xml
get test.sql nolist
format buffer
save test.sql replace