Best practice for code readability dictates that your keywords should always be in: insert your preferred style here __________.

Here’s a Twitter poll I’m running if you want to personally weigh in:


So even if we can’t all agree on what’s best, we can all agree that our tools should help us get the code we inherit or write in the format/shape that WE want.

Thankfully when it comes to Oracle SQL and PL/SQL, SQL Developer gives you a lot of options.

Format a Bunch of Code All At Once

So you open a file, or paste in a 1,000 line query. You want some help to make it a bit easier to read. One of the things the formatter offers is the ability to change the case of certain things.

The formatter won't step into your code comments.
The formatter won’t step into your code comments.

I know that’s a little hard to see, so here’s a closer look.

formatter_case2

You’ll notice the number of options here isn’t as robust as the Completion Insight bits I talk about next. We’re updating the formatter for version 4.2, and we’ll try to get you even more flexibility when it comes to the case of your code.

Format Code as You Type It

So this will set the case of your identifiers, you’ll see it immediately when you pull up a list of objects using the ctrl+space keyboard shortcut, but you’ll ALSO see it after you go to the next line of your code – you’ll see the case of your keywords and identifiers change based on this code editor preference.

lower_case_columns

You CAN disable the format as you type, so it would only apply if you're using the insight pop-ups.
You CAN disable the format as you type, so it would only apply if you’re using the insight pop-ups.

Brute Force It

Of course the editor itself also lets you make everything UPPER, lower, or InitCaps.

Select your text, and go.

You can toggle through the 3 styles, or you can go straight to UPPER or lower.

Note that the first two editor operations aren't mapped to keyboard shortcuts, so you'll have to set them if you want to use them.
Note that the first two editor operations aren’t mapped to keyboard shortcuts, so you’ll have to set them if you want to use them.
thatjeffsmith
Author

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

9 Comments

  1. Hi Jeff,
    is it correct that the toolbar button “To Upper/Lower/InitCap” on the worksheet (and by consequence also the related keyboard shortcut) is directly linked to LOV for preference “Code Editor > Completion Insight > Change case as you type” ???

    For example, I have set the above preference to “Upper Keywords, Lower Identifiers”, but whenever I click mutliple times on the toolbar button in question, the preference changes cyclically through the values “Initial Cap”, “Upper Case”, “Lower Case”, overwriting any value I have set previously.

    Then if I want to have my keywords in uppercase and identifiers in lowercase again, I have to reopen the preferences and reset the “Change case as you type” preference to the previous value.

    This is happening since several SQLDev versions, so maybe it’s an (undocumented) feature…

    Thanks for the attention,
    Paolo

  2. David Grimberg Reply

    It’s nice being able to go straight to UPPER or lower case but I keep hoping for a quick keyboard shortcut to go straight to Init Cap.

    • Matthew Holloway

      Try highlighting the desired text and + + to toggle between all caps, all lower, initcap, lower key upper identifiers and upper keyword lower identifiers.

    • Matthew Holloway

      Hmm the webpage has dropped my keys, possibly due to the tag like behavior.
      This is the key combo I meant.

      Ctrl + Shift + ‘

  3. Hi Jeff,

    When I set my “Change case as you type” property to “Lower Case”, everything works fine except for the drag and drop feature, it always creates the statement in upper case and then changes the last column only to lower case. I’m using version 4.1.3.20, but I’ve noticed the same behavior in previous versions as well.

    Thank you!

Write A Comment