文章出處

image

student表

SELECT  *  from  `student` where length(sex) = 0

 

image

SELECT  length(ID)   from  `student`  WHERE  province ='浙江'

 

image

 

length針對字符,而lengthb是針對字節的。

字符與字節的關系,如1個英文字母占一個字符,中文占兩個字符。

image

image

該軟件簡化了length與lengthb的用法?

 

Trim() 函數  

功能就是使用它來去除字符串的行首和行尾的空格,這個功能也是大家使用頻率最高的一種。

image

 

select trim(province) FROM `student` where ID IN (23,24)

 

image

 

1. trim()刪除字符串兩邊的空格。
2. ltrim()刪除字符串左邊的空格。
3. rtrim()刪除字符串右邊的空格。
4. trim('字符1' from '字符串2') 分別從字符2串的兩邊開始,刪除指定的字符1。
5. trim([leading | trailing | both] trim_char from string) 從字符串String中刪除指定的字符trim_char。
    leading:從字符串的頭開始刪除。
    trailing:從字符串的尾部開始刪除。
    borth:從字符串的兩邊刪除。
6. tim()只能刪除半角空格。

例如:

select *,trim('江'from'江蘇') FROM `student` where ID IN (23,24)

 

image

 

 

image

 

select *,trim(LEADING  'X' from 'XXXX江都' )  FROM `student` where ID = 24;

select *,trim(BOTH  'X' from '江XXXXX蘇' )  FROM `student` where ID =23;

select *,trim(trailing 'X' from '安徽XXXXXX' )  FROM `student` where ID =22;

 

image

image

image

 

******trim()函數與length()函數混用,例如:

image


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()