我自仰头向天笑,笑完我就去睡觉,哈哈哈哈……

MySQL的截取字符串和链接字符串函数

MySQL在查询或者更新数据的时候,有字符串函数可用。

截取字符串函数:substring、instr

用法如下:

update `table` set field5 = SUBSTRING(field5  , 1 , INSTR( field5 ,'-')-1) where id = 1; //这里,要从field5里面最开始一直截取到‘-’的地方(不包括‘-’)。注意,substring是从1开始,而不是一般的程序函数从0开始。

 

 

 

字符串链接函数:contact

用法如下:

update `table` set field5 = concact(field5  , 'somestr') where id = 1; //这里,要吧field5和‘somestr’链接起来,再更新到field5

 

 

posted @ 2012-12-29 10:59  轻轻的烟雾  阅读(218)  评论(0编辑  收藏  举报