sql - Where 子句语句中的动态 LIKE
问题描述
我一直在努力实现 LIKE 语句的动态查询
从下面的 SQL 查询中,而不是对每个值都执行 ilike,它可能会变大。我无法为新的 table_name 值一次又一次地重写查询。我可以将这些值存储在单独的表中,但是如何动态实现它
SELECT
t.table_name as table_name,
t.table_schema as table_schema
FROM
information_schema.tables T
WHERE (table_schema ilike 'stage' and table_name like 'ABC%') or (table_schema ilike 'stage' and table_name like 'EFG%');
我可以有另一个表,其中包含如下值列表
创建或替换表 tempdw.blk_table;( db_name varchar, tbl_expr varchar );
插入 tempdw.blk_table 值('stage','ABC%');插入 tempdw.blk_table 值('stage','EFG%');
从 tempdw.blk_table 中选择 *;
解决方案
如果您只是在寻找一组带前缀的表,您可以使用regexp_like()
:
where table_schema ilike 'stage' and
regexp(lower(table_name), '^abc|efg')
推荐阅读
- asp.net - 标签显示为字符串数组,而不是单独的
- javascript - 如何聚焦当前标签木偶
- javascript - 角 currentTarget 访问属性
- c# - 如何使用 ASP.NET Core 将查询字符串参数转换为看起来像目录部分?
- git - 如何从 GitHub 存储库中的环境中删除 github-pages?
- python - 如何使用 2 列作为条件删除 Pandas Dataframe 中的行?
- amazon-web-services - 两个或多个 ECS 服务实例之间的通信
- sql - MariaDB 无法删除名为“`”的列
- c# - 学习 MVVM。调用方法
- microsoft-graph-api - ms 图形文件上传到 sharepoint 站点