NOT IN不适用于Listagg函数

问题描述 投票:0回答:1

下面是表的DDL

  create or replace table  tempdw.blk_table;
   (
     db_name varchar,
     tbl_expr varchar
   );

   insert into  tempdw.blk_table  values ('edw','ABC%');
   insert into  tempdw.blk_table  values ('edw','ABC%');

   select * from tempdw.blk_table;

enter image description here

以下代码不起作用,预期输出不应返回任何内容

select * from tempdw.blk_table where tbl_expr not in (
       select regexp_replace(regexp_replace(replace(listagg(tbl_expr,','),',','\',\''),'^','\''),'$','\'') from tempdw.blk_table);

当我在下面的代码中运行时,它工作正常,试图理解为什么以上代码不起作用

select * from tempdw.blk_table where tbl_expr NOT IN('ABC%','EFG%');
sql oracle snowflake-cloud-data-platform
1个回答
0
投票

Au反对代码工作正常。您不了解带逗号的字符串和字符串列表之间的区别。

不幸的是,很难弄清您想要做什么,因为您的问题并不能说明这一点。我可以推测您想要类似的东西:

select bt.* from blk_table bt where db_name like tbl_expr;

但是,这只是一个猜测。
© www.soinside.com 2019 - 2024. All rights reserved.