mysql(substring函数,contact函数以及replace函数的使用)

本文介绍了一种使用MyBatis更新树状结构中节点及其子节点父ID的方法,涉及replace、concat及substring等SQL函数的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下面讲到的语法,当时的使用场景是要移动树中的节点时,要修改该节点以及其子节点的所有父节点(parentids)。

<update id="uptParentId" parameterType="map">
update trainstaff_dept set parentids = replace(parentids,#{oldPId},#{newPId}) where companyid=#{companyId}
<if test="null!=Id"> and id=#{Id} </if>
</update>

<update id="uptParentIds" parameterType="map">
update trainstaff_dept set parentids=concat(#{newPId},substring(parentids,#{length}+1)) where substring(parentids,1,#{length})=#{oldPId} and companyid=#{companyId};
</update>

substring(filed,m):截取filed字段从第m个字符开始到结束的字符串;

substring(filed,m,n):截取filed字段从第m个字符开始的长度为n的字符串;

cancat(string1,sting2,……):将string1、string2, ……字符串连接起来。

replace(parentids,#{oldPId},#{newPId})

parentids:需要替换的字段

oldPId:老的字符串

newPId:新的字符串

转载于:https://www.cnblogs.com/momo1210/p/7680710.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值