Name Last Update
build Loading commit data...
lib/blancoSQLFormatter Loading commit data...
src Loading commit data...
.gitignore Loading commit data...
1.sql Loading commit data...
README.md Loading commit data...
build.xml Loading commit data...
simplesqlbeautifier.iml Loading commit data...
simplesqlbeautifier.ipr Loading commit data...
simplesqlbeautifier.iws Loading commit data...

README.md

Simple SQL Beautifier

=========

Simple SQL Beautifier is a simple console tool for auto reformatting SQL code based that uses BlancoSQLFormatter java library.

Usage:

java -jar SQLBeautifier.jar your_file.sql

or

echo select * from dual | java -jar SQLBeautifier.jar

You can use it within SQL*plus with script like that:

set termout off timing off head off
col qtext format a1500
prompt ################################  Original query text:  ################################################;
spool &_SPOOLS/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
col qtext   clear
set termout on head on
prompt ################################  Formatted query text #################################################;
host java -jar inc/SQLBeautifier.jar &_SPOOLS/to_format.sql
prompt ################################  Formatted query text End #############################################;

For example:

SQL> @text 4ra1s6mrt008q
################################  Formatted query text #################################################
SELECT
        substrb (
            dump( val ,16 ,0 ,32 )
            ,1
            ,120
        ) ep
        ,cnt
    FROM
        (
            SELECT
                    /*+ no_parallel(t) no_parallel_index(t) dbms_stats cursor_sharing_exact use_weak_name_resl dynamic_sampling(0) no_monitoring no_substrb_pad */
                    "SNAP_ID" val
                    ,COUNT (*) cnt
                FROM
                    "SYS" . "WRH$_SGA" t
                WHERE
                    "SNAP_ID" IS NOT NULL
                GROUP BY
                    "SNAP_ID"
        )
    ORDER BY
        val

################################  Formatted query text End #############################################

Sayan Malakshinov

Site: orasql.org

Git repository: src.orasql.org