SQL去除空格、截取數據的方法:trim、substring


1、如device表中的identity字段正常的字段長度是32位,但是某些不正常的數據,后面多出空格,需要去掉后面的空格,可執行以下命令:

1 select * from device where length(identity)=33;
2 update device set identity=trim(identity) where length(identity)=33;

2、使用substring函數截取某字段的的其中一部分的方法,如截取identity第21位及其之后的數據,並保存位identity12字段:

1 update device set identity12=substring(identity,21);

 


免責聲明!

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



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