码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2017-10-17 15:32:56      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:tin   concat   子节点   移动   null   修改   场景   set   length   

下面讲到的语法,当时的使用场景是要移动树中的节点时,要修改该节点以及其子节点的所有父节点(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:新的字符串

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

标签:tin   concat   子节点   移动   null   修改   场景   set   length   

原文地址:http://www.cnblogs.com/momo1210/p/7680710.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!