Skip to content
Advertisement

Oracle sql | Share generated by default on null as identity

Is it possible to share the same “pool” for ids when using following syntax?

When both attribute have the same name? The only possibility I came up was to start both at different values. Like Test on 1000 and test 2 on 2000 but this is not a long term solution. I’m looking to a solution where I can “share” the same “pool” for ids, so that the id’s will never overlap.

Advertisement

Answer

You can use DEFAULT ON NULL with a sequence:

Then if you insert some data:

Then:

| ID |
| -: |
|  1 |
|  4 |
| ID |
| -: |
|  2 |
|  3 |

db<>fiddle here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement