从 Oracle 12c 开始,我们可以使用 IDENTITY 字段。
有没有办法检索最后插入的身份(即 select @@identity
或 select LAST_INSERTED_ID()
等等)?
原文由 bubi 发布,翻译遵循 CC BY-SA 4.0 许可协议
从 Oracle 12c 开始,我们可以使用 IDENTITY 字段。
有没有办法检索最后插入的身份(即 select @@identity
或 select LAST_INSERTED_ID()
等等)?
原文由 bubi 发布,翻译遵循 CC BY-SA 4.0 许可协议
正如我在 这篇博 文中所写,您可以通过单个查询获取架构的所有当前标识值:
with
function current_value(p_table_name varchar2) return number is
v_current number;
begin
for rec in (
select sequence_name
from user_tab_identity_cols
where table_name = p_table_name
)
loop
execute immediate 'select ' || rec.sequence_name || '.currval from dual'
into v_current;
return v_current;
end loop;
return null;
end;
select *
from (
select table_name, current_value(table_name) current_value
from user_tables
)
where current_value is not null
order by table_name;
/
原文由 Lukas Eder 发布,翻译遵循 CC BY-SA 4.0 许可协议
1 回答2.4k 阅读✓ 已解决
1 回答2.3k 阅读✓ 已解决
1.4k 阅读
出色地。 Oracle 在 12c 中为 IDENTITY 功能使用序列和默认值。因此,您需要了解您的问题的序列。
首先创建一个测试标识表。
首先,让我们找到使用此标识列创建的序列名称。此序列名称是表中的默认值。
对我来说,这个值是“ISEQ$$_193606”
插入一些值。
然后插入值并找到身份。
你应该看到你的身份价值。如果你想在一个块中使用
最后一个 ID 是我的身份列名称。