sql - PL/SQL 循环遍历列表并查找数据库表中不存在的值
问题描述
我有一个名单。但是这个列表很大(10000+ 项)。我想浏览这个值列表并列出表中不存在的值。
我能够想出这个,
select i.column_value as country_code
from table(SYS.DBMS_DEBUG_VC2COLL('AU', 'IN', 'ZA', 'DK', 'CH', 'NL')) i
where not exists (select null
from country c
where c.country_code = i.column_value)
但它将提供给函数的值的数量限制为 1000。因此我无法立即提供完整列表
ORA-00939: too many arguments for function
有谁知道解决这个问题。
解决方案
如果您真的被固定的值列表所困扰,您可以在子查询(内联视图)中将几个表集合表达式联合在一起:
select i.column_value as country_code
from (
select * from table(SYS.odcivarchar2list(
'AU', 'IN', 'ZA', 'DK', 'CH', 'NL' -- up to 999 entries
))
union all
select * from table(SYS.odcivarchar2list(
'AU', 'IN', 'ZA', 'DK', 'CH', 'NL' -- up to 999 entries
))
) i
where not exists (select null
from country c
where c.country_code = i.column_value)
我倾向于使用odcivarchar2list
而不是dbms_debug_vc2coll
,但它应该适用于任何一个。
如果数据在文件中,并且您可以在数据库服务器上使其可用,则可以将其作为外部表加载,这将减少手动工作。
推荐阅读
- c - 无法使用共享 C 库中的函数 cpuset_create
- google-bigquery - 在 bigquery 中拆分字符串
- python - 如果满足条件,则迭代数据帧的行并检索列的值
- wordpress - 如何访问 azure 上的 Wordpress 文件和我的 wp-admin 显示 403 禁止错误
- android - 有什么方法可以拦截 android 上 WebView 上的 websocket 连接?
- javascript - 在选项卡更改时触发窗口重新加载以更新 React 中的选项卡内容
- elasticsearch - 弹性嵌套布尔查询的输出之间的差异
- r - 在 geom_point 中填充区域
- pentaho - Pentaho91:将数据网格行复制到两个合并连接。这是一个错误吗?
- css - 居中可折叠但内容下降