You could try a formatter like this
They will always be limited because they don’t (and can’t) know what user defined functions you may have defined in your database (or which built-in functions you have or don’t have access to).
You could also look at ANTLR (but that would be an offline solution)