[编辑]
Ah ..迭代时如何放置“ 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"
我如何实现我的目标?
谢谢..
[EDIT]目前附加的文本文件。
链接已删除...
在没有此查询的情况下执行时,其运行时会立即生效。不需要时间。但是,当我执行此查询时,我花了71秒才能完成。我猜我犯了一些错误。其他XML部分已由其他查询处理,该查询仅处理上述标记。
答案 0 :(得分:2)
使用递归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>%';
请参见demo。
结果:
| myCOL |
| ---------------- |
| abc■def |
| abc■def..ghi■jkl |