blogspot.com-GA4

星期一, 12月 14, 2009

MySQL:常用字串函數

select ASCII('A')=65

select CONCAT('ASD','ERT')=ASDERT
說明:字串相加

select LOCATE('78','1234567890')=7

select LTRIM(' asdfgh) =asdfgh
說明:消除左邊空格

select RTRIM('asdfasdf ')=asdfasdf
說明:消除右邊空格

select TRIM(' mysql 常用字元 ')=mysql 常用字元
說明:截掉前後的空白字元

select MID('asdfghjkl',2,3) =sdf

select POSITION('fa' in 'sdfasdfasdfasdf')=3
說明:fa在較長字串中的位置

select REPEAT('asdf',4) =asdfasdfasdfasdf
說明:重複4次字串

select RIGHT('abcdefgh',4) =efgh
說明:從右數過來第四個字元開始的字串。

select SPACE(10)=' '
說明:造出十個空格字元

select SUBSTRING('abcdefghij',4)=defghij
說明:從左邊第四個字元擷取起

select SUBSTRING('abcdefghij' from 4)=defghij
說明:同上

select SUBSTRING('abcdefghij',4,2)=de
說明:從左邊第四個字元擷取兩個字元

select SUBSTRING('abcdefghij' from 4 for 2)
說明:同上

select UCASE('mysql5.0')=MYSQL5.0
說明:將字串轉為大寫

select LOWER('MYSQL5.0')=mysql5.0
說明:將字串轉為小寫

select LENGTH('abcdefghij')=10
說明:字串長度 =12AG56789

select INSERT('123456789',3,2,'AGWE')=12AGWE56789
說明:取代第3個位置函數

select INSTR('ASDFGHHG','DF')=3
說明:傳回DF在字串中的位置

select HEX(ASCII('A'))=41
說明:傳回16進位字串

select ELT(3,'A','B','C','D') =C
說明:判斷函數,1=A、2=B、...

select FIELD('CC','AA','BB','CC')=3
說明:判斷函數,如果CC=AA則等於1

來源:http://dalada.blogspot.com/2007/12/mysql.html

沒有留言: