MySQL數(shù)據(jù)庫中字符串的處理方法
以下的文章主要向大家描述的是MySQL數(shù)據(jù)庫存儲過程基本函數(shù)類型即字符串,MySQL字符串在實際操作中還是經(jīng)常被用到的,以下的文章主要是對MySQL字符串的時機(jī)應(yīng)用與相關(guān)功能的描述。
字符串類
CHARSET(str) //返回字串字符集
CONCAT (string2 [,... ]) //連接字串
INSTR (string ,substring ) //返回substring***在string中出現(xiàn)的位置,不存在返回0
LCASE (string2 ) //轉(zhuǎn)換成小寫
LEFT (string2 ,length ) //從string2中的左邊起取length個字符
LENGTH (string ) //string長度
LOAD_FILE (file_name ) //從文件讀取內(nèi)容
LOCATE (substring , string [,start_position ] ) 同INSTR,但可指定開始位置
LPAD (string2 ,length ,pad ) //重復(fù)用pad加在string開頭,直到字串長度為length
LTRIM (string2 ) //去除前端空格
REPEAT (string2 ,count ) //重復(fù)count次
REPLACE (str ,search_str ,replace_str ) //在str中用replace_str替換search_str
RPAD (string2 ,length ,pad) //在str后用pad補(bǔ)充,直到長度為length
RTRIM (string2 ) //去除后端空格
STRCMP (string1 ,string2 ) //逐字符比較兩字串大小,
SUBSTRING (str , position [,length ]) //從str的position開始,取length個字符,
注:MySQL數(shù)據(jù)庫中處理字符串時,默認(rèn)***個字符下標(biāo)為1,即參數(shù)position必須大于等于1
- MySQL> select substring('abcd',0,2);
- +-----------------------+
- | substring('abcd',0,2) |
- +-----------------------+
- | |
- +-----------------------+
- 1 row in set (0.00 sec)
- MySQL> select substring('abcd',1,2);
- +-----------------------+
- | substring('abcd',1,2) |
- +-----------------------+
- | ab |
- +-----------------------+
- 1 row in set (0.02 sec)
- TRIM([[BOTH|LEADING|TRAILING] [padding] FROM]string2)
去除指定位置的指定字符
UCASE (string2 ) //轉(zhuǎn)換成大寫
RIGHT(string2,length) //取string2***length個字符
SPACE(count) //生成count個空格
以上的相關(guān)內(nèi)容就是對MySQL數(shù)據(jù)庫存儲過程基本函數(shù)中的字符串的介紹,望你能有所收獲。
【編輯推薦】