Just because you’re in a command line interface doesn’t mean you’re stuck with ugly code!

Wait, if it’s my code, you’re stuck with ugly code.

But if it’s YOUR code, then you’re not stuck with poorly formatted code.

You can of course use the FORMAT command to format what’s in a file or in the SQLcl buffer.

I don’t like the formatter default settings!

Have no fear.

Load up the GUI.

Yes, THAT GUI.

Set your preferences.

Save them.

Set it and forget it?

Go back to SQLcl, load the formatter rules.

remember, you have HELP for each command and for each SET[ting] in SQLcl!

Before the format…

I want leading commas!

Ok, let’s format that.

Most of you will hate this formatting scheme.

Easy-peasy!

Note I did with this the latest copy of SQLcl – updated just LAST WEEK – and a pre-production version of version 4.2 of SQL Developer which you folks will be able to get access to later this year.

Here’s SQLcl using formatter settings applied from EA2, so that SHOULD work for those of you using the EA.

My code’s not ugly, YOUR code is ugly πŸ™‚
Author

I'm a Distinguished Product Manager at Oracle. My mission is to help you and your company be more efficient with our database tools.

12 Comments

  1. Slavko Brkic Reply

    Hi Jeff,

    Thanks for your answer. We actually got it working by keeping runOnce and removing false. Sorry for the inconvenience

    BR,
    Slavko

  2. Slavko Brkic Reply

    Hi Jeff,

    I found the following in the arbori file which comes included with the Sql developer 22 release.

    timestamp: runOnce & false -> {
    var date = new java.util.Date();
    var formatted = “/* Formatted by SqlDev on “;
    var index = target.input.indexOf(formatted);
    if( index != 0 )
    struct.putNewline(0, formatted+date+” */\n”);
    else {
    var timestampEnd = target.input.indexOf(” */”);
    target.input = formatted+date+target.input.substring(timestampEnd);
    }
    }

    This seems like there should be some functionality to add /* Formatted by SqlDev on */ on the first line of source code. This is exactly what we are interested in. However it does not seems like it is doing anything. Is there a toogle that needs to be set for the formatter to add this line?

    BR,
    Slavko

  3. Hi Jeff
    As we have specific custom formatting and your previous answer was that only the XML one can be loaded, how about the within the XML. This points to the arbori (custom formatting) file. But it seems the formatter is ignoring it? Looks so to me as I didn’t manage it so far that the arbori is being used.
    Will there be maybe in the future the possibility or feature to load also the arbori or that it is loaded based on the XML configuration?

  4. Hi
    I am using sql developer 19.4 and sqlcl 19.4. format setting has Keyword as LOWER case but even after loading ( using format rules ) i am not seeing changes in sqlcl.
    Thanks
    Anand

  5. Mikhail Orlov Reply

    I tried exporting the XML from SQL Developer 3.20 and using it in sql.exe 18.3. The file loads correctly (“Formatter rules loaded”), but doesn’t seem to have any effect. I even tried removing all unnecessary profiles from it, but still the formatting works with some general rule set. For example, I enabled line breaks before commas, but it is inserted after them.

    • sqldev 3.2 is…ancient, and has a completely different formatter

      get a sqldeveloper 18.3 and setup your formatter there

    • Mikhail Orlov

      OK, so I obviously used some ancient version of SQL Developer which has a completely different system. Strange to see sql.exe not writing any errors instead!

      Also it feels that that old version had more granular options.

    • what are you looking for that you can’t find?
      >>more granular – doesn’t give me much to work with

  6. Robert Ohajda Reply

    Hi,
    In SQL Developer there are two files related to formatting. One is XML from advanced option and another is custom formatting with file extension prg. How to set both if I have modified advanced format and custom format as well?

    Thanks Robert

Reply To dafis Cancel Reply