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:
Do you agree? Best coding practices dictate uppercase identifiers? https://t.co/WhOZvL2Bmv
— Jeff Smith ☜ (@thatjeffsmith) March 16, 2016
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.
I know that’s a little hard to see, so here’s a closer look.
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.
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.
9 Comments
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
I believe they are connected, yes
I thought so.
Wouldn’t it make it more sense to let it cycle through all the values in the LOV instead of only those 3?
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.
Try highlighting the desired text and + + to toggle between all caps, all lower, initcap, lower key upper identifiers and upper keyword lower identifiers.
Hmm the webpage has dropped my keys, possibly due to the tag like behavior.
This is the key combo I meant.
Ctrl + Shift + ‘
On my machine, it’s ALT + ‘ –> and it works as expected.
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!
camelCase 😉