从标识列的支持序列获取 nextval
Getting nextval from a backing sequence of an identity column
我有一个这样声明的 table 列:
file_id number(10) generated always as identity primary key,
是否可以通过编程方式从其支持序列中获取 currval
/nextval
而无需实际查看 SYS. tables 获取序列的名称,然后在该名称上使用 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
我有一个这样声明的 table 列:
file_id number(10) generated always as identity primary key,
是否可以通过编程方式从其支持序列中获取 currval
/nextval
而无需实际查看 SYS. tables 获取序列的名称,然后在该名称上使用 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