栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

用查询中的值替换字段的一部分

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用查询中的值替换字段的一部分

也许不是最有效的方法,但是它是递归工作的(也就是说,如果它

crit_description
本身包含“占位符”,那么这些占位符也会被扩展。(第一个解决方案比下面的显示更简单,没有执行此递归步骤。)我添加的第三个示例输入。如果可以再清理一些,我将在以后再次发布。

注意:这假定在

criteria_info
表中实际找到所有“占位符” 。我没有测试如果找不到它们会发生什么。OP陈述要求。

with     inputs ( criteria ) as (       select '$1 = True' from dual union all       select '$2 > $3'   from dual union all       select '$1 = $4'   from dual     ),     criteria_info ( crit_id, crit_description ) as (       select 1, 'Example 1' from dual union all       select 2, 'Example 2' from dual union all       select 3, 'Example 3' from dual union all       select 4, '$2 + $3'   from dual     ),     rec ( criteria, new_str ) as (       select  criteria, criteria         from  inputs    union all   select  r.criteria,     regexp_replace(r.new_str, '$d+', c.crit_description, 1, 1)         from  rec r inner join criteria_info c    on to_number(regexp_substr(r.new_str, '$(d+)', 1, 1, null, 1)) = c.crit_id         where regexp_substr(r.new_str, '$d+') is not null     )select criteria, new_strfrom   recwhere  regexp_substr(new_str, '$d+') is null;CRITERIA  NEW_STR--------- ------------------------------------$1 = True Example 1 = True$2 > $3   Example 2 > Example 3$1 = $4   Example 1 = Example 2 + Example 33 rows selected.


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/495324.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号