Oracle SQL 查找所有表中的最高 ID
我的每一张表都有一个“id”字段。考虑到表列表可能会发生变化,我需要能够找到所有表中的最高 ID。
有什么方法可以获取oracle数据库中的表列表,聚合它们的行(仅id),然后获取max()
?
PS 这是为了更新已经不正常的序列。
Every one of my tables has an "id" field. I need to be able to find the highest ID across all of them, given that the list of tables might change.
Is there any way to get the list of tables in an oracle database, aggregate their rows (only ids), and then get the max()
?
P.S. This is for updating a sequence which has gone out of whack.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面是一些驱动数据字典的简单动态 SQL:
如果序列服务表跨多个模式,则需要驱动 ALL_TAB_COLUMNS 并在查询中包含 OWNER。
Here is some simple dynamic SQL driving off the data dictionary:
If the sequence services tables across several schemas, you will need to drive off ALL_TAB_COLUMNS and include OWNER in the query.
这个怎么样?
对需要搜索的所有表重复 UNION ALL。
How about this?
Repeat the UNION ALL for all tables that you need to search from.
如何查询驱动 id 的 CURRVAL 序列?
如果您还需要找出 id 所在的表,那么构建一个新表来集中跟踪 id 并添加触发器以在插入时填充。
how about querying the sequence that drives the id's for CURRVAL...
if you need to find out also what table that id is in, then construct a new table to track the id centrally and add triggers to populate on insert.