我正在尝试编写一个plsql查询,它允许我查询一组未存储在表中的已知值。 假设这些已知值是以下字符串:
我想实现以下目标:
select * from [fill-in-the-blank] myvalues
where not myvalues in
(
select id from dbtable
)
..我试图确定哪些知识值不在数据库表中。
约束
有什么想法吗?
答案 0 :(得分:5)
您可以使用公用表表达式(CTE)来完成此任务:
with cte as (
select 'abc' as id from dual
union all
select 'def' from dual
union all
select 'ghi' from dual
union all
select 'jkl' from dual
)
select *
from cte
where not id in
(
select id from dbtable
)
事实上,你可能根本不需要CTE(虽然我发现它有助于提高可读性):
select *
from (
select 'abc' as id from dual
union all
select 'def' from dual
union all
select 'ghi' from dual
union all
select 'jkl' from dual
)
where not id in
(
select id from dbtable
)
答案 1 :(得分:0)
旧线程我知道,但没有人提到
select * from table(sys.dbms_debug_vc2coll('abc','def','ghi','jkl'));
当然,您不必使用sys.dbms_debug_vc2coll
。可以使用以下列出可用的集合类型:
select c.owner, c.type_name, c.elem_type_name, c.length
from all_coll_types c
where c.coll_type = 'TABLE'
and c.elem_type_name = 'VARCHAR2'
order by 1,2;