Previously i wrote beautifier in perl, but it was not so good, so i decided to write it in java using popular BlancoSQLFormatter library.
So you can download it now: https://orasql.org/scripts/SQLBeautifier.jar
Usage:
java -jar SQLBeautifier.jar your_file.sql
or
echo select * from dual | java -jar SQLBeautifier.jar
You certainly can conveniently use it within sql*plus with script like that:
set timing off head off termout off
col qtext format a150
prompt ################################ Original query text: ################################################;
#spool &_SPOOLS/to_format.sql
spool to_format.sql
select
coalesce(
(select sql_fulltext from v$sqlarea a where a.sql_id='&1')
, (select sql_text from dba_hist_sqltext a where a.sql_id='&1' and dbid=(select dbid from v$database))
) qtext
from dual
;
spool off
prompt ################################ Formatted query text #################################################;
#host perl inc/sql_format_standalone.pl &_SPOOLS/to_format.sql
host java -jar SQLBeautifier.jar to_format.sql
prompt ################################ Formatted query text End #############################################;
set termout on head on
Links:

