1

sqlcl appears to use the formatting rules when formatting the buffer, but ignores them for formatting a file.

I have an input file (test.sql) and a small set of formatting rules (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>

An sqlcl session showing the rules applied to the buffer, not to the file:

[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 ~]$

Setting SQLFORMATPATH doesn't work either:

[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
Alistair Bayley
  • 331
  • 2
  • 14

1 Answers1

0

Loading file into the buffer, format it there and save it back can be a workaround:

  format rules format.xml
  get test.sql nolist
  format buffer
  save test.sql replace
mtexpert
  • 1
  • 1