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


下面講到的語法,當時的使用場景是要移動樹中的節點時,要修改該節點以及其子節點的所有父節點(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:新的字符串


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM