[英]PL/SQL Loop through a list and find values which not exists in database table
I have a list of names.我有一个名字列表。 But this list is quite big(10000+ items).但是这个列表相当大(10000+ 项)。 I want to go through this values list and list down values which doesn't exist in the table.我想查看此值列表并列出表中不存在的值。
I was able to come up with this,我能够想出这个,
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)
but it limits the number of values to be provided to the function as 1000. Thus I'm not able to give to provide full list at once但它将提供给函数的值数量限制为 1000。因此我无法一次提供完整列表
ORA-00939: too many arguments for function
Does anyone know a solution to this.有谁知道这个问题的解决方案。
If you're really stuck with fixed lists of values, you could union together several table collection expressions, in a subquery (inline view):如果您真的坚持使用固定值列表,则可以在子查询(内联视图)中将多个表集合表达式联合在一起:
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)
I tend to use odcivarchar2list
rather than dbms_debug_vc2coll
but it should work with either.我倾向于使用odcivarchar2list
而不是dbms_debug_vc2coll
但它应该可以使用。
If the data is in a file and you can make that available on the database server you might be able to load it as an external table , which would involve less manual work.如果数据在一个文件中并且您可以在数据库服务器上提供该数据,则您可以将其作为外部表加载,这将减少手动工作。
Agree with Alex that external table is the way to go, assuming you have permissions to set up a directory and copy the file to the database server.同意 Alex 的观点,假设您有权设置目录并将文件复制到数据库服务器,则外部表是可行的方法。 A quick bet would be to query all_directories
for existing directories and see if you have access to copy your file there.一个快速的选择是查询all_directories
以获取现有目录,并查看您是否有权将文件复制到那里。 Also, dba_external_tables
would show you existing external tables (if any) that you can describe to show the syntax.此外, dba_external_tables
会向您显示现有的外部表(如果有),您可以描述这些表以显示语法。
If you're lacking permissions, you may want to explore SQL Loader sqlldr
to load the codes from raw file onto a database table, which will then make your query easier and faster.如果您缺乏权限,您可能想要探索SQL Loader sqlldr
将原始文件中的代码加载到数据库表中,这将使您的查询更容易、更快。
In sqlldr
use OPTIONS (DIRECT=TRUE, PARALLEL=TRUE) UNRECOVERABLE
to speed up the load.在sqlldr
使用OPTIONS (DIRECT=TRUE, PARALLEL=TRUE) UNRECOVERABLE
来加速加载。
Good luck and chat back here if you need more help.祝您好运,如果您需要更多帮助,请回到这里聊天。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.