mysql中replace函数直接替换mysql数据库中某字段中的特定字符串,不再需要自己写函数去替换,用起来非常的方便,mysql 替换函数replace()
Update `table_name` SET `field_name` = replace (`field_name`,’from_str’,'to_str’) Where `field_name` LIKE ‘%from_str%’
实例:把'病假' 替换为 '--':UPDATE users SET username=REPLACE(username,'病假','--') WHERE username LIKE '%病假%'
说明:
table_name —— 表的名字
field_name —— 字段名
from_str —— 需要替换的字符串
to_str —— 替换成的字符串
字符串函数select substring('abcde',3,2)select upper('abCD123')select lower('abCD123')select ltrim(' abc')select rtrim(' abc ') --将一个字符串插入到另一字符串。在插入新字符串时将从原来的字符串中删除指定长度的字符--stuff(string, insertion position, delete count, string inserted)select stuff('abcdef',3,2,'1234') --Replace(source, search, replace)select replace('abcd','cd','fe') 时间函数--获取当前日期select getdate()--对日期进行减运算select DateDiff(yy,' 1984/5/20',GetDate())AS MarriedYears--对日期进行加运算select DateAdd(hh,100,GetDate()) AS [100HoursFromNow]--返回datetime值的指定日期部分的整数值select DatePart(DayofYear,GetDate())As DayCount--从日期中获取年,月,日select day('03/12/1998') as [Day] ,month('03/12/1998') as [Month], year('03/12/1998') as [Year]回答完毕欢迎分享,转载请注明来源:内存溢出
评论列表(0条)