无序自动递增

时间:2015-11-18 18:48:38

标签: oracle

我有一个select语句,之后生成set值我希望将这组值插入到另一个表中,我关心的是我在select中使用select语句我正在使用一个select select子句((select max(org_id) )来自组织的+1))我试图获得最大值并增加1但我无法获得增量值而不是我得到相同的值你可以看到列名id_limit

select abc,abc1,abc3,abc4,(select max(org_id)+1 from org) as id_limit from xyz

current output    
    -----------------------------------------------------------------
     | abc           |  abc1       |   abc3 | abc4   | id_limit     |
     ----------------------------------------------------------------|
     | BUSINESS_UNIT |    0        |   100  | London | 6            |
     | BUSINESS_UNIT |    0        |   200  | Sydney | 6            |
     | BUSINESS_UNIT |    0        |   300  | Kiev   | 6            |
     -----------------------------------------------------------------

我正在尝试预期输出

     -----------------------------------------------------------------
     | abc           |  abc1       |   abc3 | abc4   | id_limit     |
     ----------------------------------------------------------------|
     | BUSINESS_UNIT |    0        |   100  | London | 6            |
     | BUSINESS_UNIT |    0        |   200  | Sydney | 7            |
     | BUSINESS_UNIT |    0        |   300  | Kiev   | 8            |
     -----------------------------------------------------------------

1 个答案:

答案 0 :(得分:2)

是的,在Oracle 12中。

create table foo (
  id number generated by default on null as identity
);

https://oracle-base.com/articles/12c/identity-columns-in-oracle-12cr1

在以前的版本中,您可以使用序列/触发器,如下所述:

How to create id with AUTO_INCREMENT on Oracle?