I Say Snippet, Snippet Good: SQL Developer Snippets

There’s nothing worse than the ‘white screen of panic.’ You’re faced with the prospect of actually writing some code from scratch. Or even worse, you’re doing a presentation or demo, and everyone gets to see what a horrible typist you are.

Yes, this is about Snippets, and Snippets are cool. But if you’re a keyboard person, then you’re gonna like SQL Templates even better. Go read this and come back. -TJS 3/13/15

The white screen of panic

Yes, you could browse your SQL History, but that could contain several hundred or even thousands of statements. And let’s face it, you probably don’t recognize code you wrote even a few days ago when you see it.

Wouldn’t it be nice if you could take your favorite statements or scripts, and save them to recall later? Even better, let me name and document them?

Enter the Snippets

Access your snippets via the View menu. There’s a few included ‘out of the box,’ but you’ll want to add your own to the ‘Custom’ category.

Access the Snippets from the View menu

Add a Snippet

The easiest way to add a snippet is to select your code and right-click. Choose ‘Save as Snippet…’

You can do this for a single statement or multiple statements (scripts)

Define the Snippet

Place it into the proper category, give it a name, and define the tool-tip that will appear if you mouse-over the snippet.

The tool-tip is optional

Snippets in Action

Now when you get back to the white-screen-of-panic, remember your trusty statements and scripts are accessible via the Snippets panel. Select your snippet and drag and drop (d-n-d) it into the worksheet or Procedure Editor. The d-n-d will respect any code you already have in your editor, meaning you can drag it exactly where you want to drop it and preserve your existing code.

Hi Jeff.
I’m an Oracle developer spending much time on SQL Developer.
I really like this tool but i miss one thing from the tool i used before (PL Dev, not to name it) and it is the ability to affect an “accelerator” for a snippet.
For exemple when you type “s*” and press the space bar after it, the “s*” turns into “select * from “. It can save so much typing !
They have the same thing in eclipse (e.g. : syserr = system.Err.println..)
Do you thing it can be possible to implement this feature in SQL Dev ?
I mean it can just be a property of a snippet.
Anyway, keep up the good work on SQL Dev, cause it’s getting more and more powerfull and i really appreciate the product and your blog.
Thanks

Do you mean like what we have for SQL Editor Code Templates? You invoke them with the auto-complete keystroke, which is ctrl+spacebar by default. They’re defined in the Preferences under the Database page.

Ah, snippets, quite an underused feature of SQL Dev. I’ve been using Snippets since my earliest SQL dev days – especially so since I had a bunch of SQL statements that I’d run to verify my data before starting a humongous data conversion job.

I think your blog post about Snippets is good enough 😉 The only other tips I’d suggest is

– If you’re using the snippets often, it’d be a good idea to keep the window docked
– I believe you can also add custom categories – having snippets categorized instead of having them all under “Custom” allows for easy discovery of snippets.
– The snippets are stored in %appdata%\SQL Developer\UserSnippets.xml file, it’d be prudent to keep the file backed up regularly. Or have a bunch of snippets pre-built and saved in the folder to save time

Thanks for the offer Ivan, but I’m not looking to have my content syndicated/translated at this point just yet. I’d be happy to guest post on your blog though, just give me a topic you and your readers would like to know more about!

And again – thanks for asking. Many folks just grab content they want, and act offended when you ask them to stop.