3

In Oracle 12c, it's possible to use AUTO_INCREMENT functionality by using the keywords/phrase GENERATED ALWAYS AS IDENTITY. This seems cumbersome/clunky to me, given that in other dialects of SQL that I'm used to (SQLite, MySQL), the same is achieved with the keyword AUTO_INCREMENT or AUTOINCREMENT.

Is it possible to create an alias/shortcut/makro/function to get Oracle to treat AUTO_INCREMENT as meaning the same as GENERATED ALWAYS AS IDENTITY? (I'm not proposing editing the source code as a practical solution. I'd rather submit a feature request.)

1
  • 1
    As far as feature requests go, you could probably ask @thatjeffsmith to add a shortcut to SQL Developer.
    – Philᵀᴹ
    Jul 13, 2018 at 13:14

1 Answer 1

9

You can tell the tool, in this case SQL Developer, to do it for you.

I talk about how to set this up here https://www.thatjeffsmith.com/archive/2014/02/auto-replace-in-oracle-sql-developer/

But basically, you define a code template in the preferences with the code you want to be recognized as a template, and then the code you want inserted.

If there is only one match for your template, when you invoke it with ctrl+spacebar, it automatically inserts the code.

If there are multiple matches, it prompts you for what you want.

I built two, one for

  1. auto_increment - long form
  2. autoincrement - short form

enter image description here

You could of course submit an enhancement request for the database so this keyword would be honored, but that's a years long process, assuming it even gets accepted and implemented.

4
  • Thank you for that answer. Unfortunately, I can't get it to work. I've followed the instructions in your blog post, but to no avail, even after closing the editor and reopening it. For reference, I'm using SQL Developer version 18.2.0.183, Build 183.1748 on Windows 10 x64, Java 9.0.1 x64 Jul 13, 2018 at 13:54
  • 2
    that's the exact version i'm using too, send me an email with screenshots at [email protected] Jul 13, 2018 at 14:05
  • Unfortunately, I can't get my screen recorder to capture when I type <kbd>Ctrl</kbd> + <kbd>Space</kbd>. The screencast is here. Not even the built-in templates (such as ct) work. Jul 13, 2018 at 14:51
  • 1
    I don't have Win Media Player, so that file doesn't give me anything. Can you do like I asked and just send me a screenshot of your editor and preferences showing me what you're trying? Jul 13, 2018 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.