[编辑]
嗯..如何在迭代时设置“ IF”条件?有时根本没有标签。
在那种情况下,我不需要任何修改。
我这样写查询;
UPDATE myTable SET myCOL =
substr(myCOL, 1, instr(myCOL, '<Tag>') - 1)
|| '■' ||
substr(myCOL, instr(myCOL, '</Tag>') + 6, length(myCOL));
因为我想这样实现
myVar := "abc<Tag>BuLah..BuLah..</Tag>def"
myGoal := "abc■def"
到现在为止还挺好。
现在,事情进入了现实世界,我的myVar像这样;
myVar := "abc<Tag>BuLah1..</Tag>def..ghi<Tag>BuLah2..</Tag>jkl"
我如何实现我的目标?
谢谢..
[编辑]目前附加了文本文件。
链接已删除...
当我在没有此查询的情况下执行时,其运行时间会立即变为 不需要时间。但是,当我执行此查询时,我花了71秒才能完成。我猜我犯了一些错误。其他XML部分已由其他查询处理,此查询仅处理上述标记。
使用递归CTE:
with recursive cte as (
select myCOL,
substr(myCOL, 1, instr(myCOL, '<Tag>') - 1)
|| '■' ||
substr(myCOL, instr(myCOL, '</Tag>') + 6, length(myCOL)) newCOL
from myTable
where myCOL like '%<Tag>%'
union all
select c.myCOL,
substr(c.newCOL, 1, instr(c.newCOL, '<Tag>') - 1)
|| '■' ||
substr(c.newCOL, instr(c.newCOL, '</Tag>') + 6, length(c.newCOL)) newCOL
from cte c
where c.newCOL like '%<Tag>%'
)
update myTable
set myCOL = (
select newCOL from cte
where myTable.myCOL = cte.myCOL and cte.newCOL not like '%<Tag>%'
)
where myCOL like '%<Tag>%';
参见演示。
结果:
| myCOL |
| ---------------- |
| abc■def |
| abc■def..ghi■jkl |
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句