oracle – 从标识列的后备序列获取nextval

前端之家收集整理的这篇文章主要介绍了oracle – 从标识列的后备序列获取nextval前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个像这样声明的表列:

file_id number(10) generated always as identity primary key,

是否有可能以编程方式从其后备序列中获取currval / nextval而无需实际查看SYS.表获取序列的名称,然后在该名称上使用execute immediate?

解决方法

Is it possible to programatically get a currval/nextval from its
backing sequence without actually looking into the SYS

是的,如果你真的需要这样做的话.您可以在USER_SEQUENCES数据字典视图中查找该序列名称,或者更好的是USER_TAB_IDENTITY_COLS数据字典视图,并在查询中引用它.这是一个例子:

create table t1(
  c1 number  generated always as identity primary key
);

insert into t1 values(default);

select *  from t1;

C1
-----
    1

在我的例子中,Oracle为标识列创建的序列名称是ISEQ $$_ 92984.

select "ISEQ$$_92984".nextval from dual;

NEXTVAL
-------
     2

insert into t1 values(default);

select * from t1;

 C1
 ---------
         1
         3

猜你在找的Oracle相关文章