mysql中的常用函数总结

基本函数

测试表:

image

一、字符串函数

  • charset(str):返回字符串的字符集

image

  • concat(str1,[…]):连接字符串

image

  • instr(string,substring):返回substring首次在string中出现的位置,若不存在则返回0

image

  • ucase(str1):字符串转换成大写
  • lcase(str1):字符串转换成小写

image

  • right(string,length):从右边起取string的length个字符
  • left(string,length):从左边起取string的length个字符

image

  • length(string):返回string的长度

image

  • load_file(file_name):从文件读取内容


  • locate(substr,str[,position]): sunstr在str中首次出现的位置,可以指定开始位置

image

  • lpad(string,length,pad):使用pad左边补齐string,指定string长度为length

image

  • rpad(string,length,pad):使用pad右边补齐string,指定string长度为length

image

  • trim(string):去除string左右两边的空格
  • ltrim(string):去除string左边的空格

image

  • rtrim(string):去除string右边的空格

image

  • repeat(string,count):重复string一共count次

image

  • replace(str,serach_str,replace_str):将str中的search_str替换为replace_str

image

  • strcmp(str1,str2):逐字符比较两字符串大小

image

  • substring(str,position[,length]):从str的position位置开始截取length个字符串

image

二、数学函数

  • abs(num1):获取num1的绝对值

image

  • bin(decimal_num):十进制转二进制

image

  • ceiling(num1):向上取整

image

  • floor(num1):向下取整

image

  • conv(num1,from_base,to_base):进制转换

image

  • format(num1,decimal_place):保留小数位数

image

  • hex(decimal_num):转十六进制

image

  • least(num1,num2,…):求最小值

image

  • mod(numerator ,denominator):求余

image

  • power(num1,power):求指数

image

  • rand(seed):求随机值

image

  • sqrt(num1):开平方

image

  • round(num1[,decimal]):四舍五入,decimals为小数位数

image

三、日期函数

  • addtime(date1,time_interval):将time_interval加到date1

image

image

  • convert_tz(datetime1,fromTZ,toTZ): 转换时区

image

  • current_date():当前日期

image

  • current_time():当前时间

image

  • current_timestamp():当前时间戳

image

  • date(datetime):返回datetime的日期部分

image

  • date_add(date,interval d_value d_type):在date中加上日期或时间

image

image

  • date_format(datetime,formatCodes):使用formatcodes的格式显示datetime

image

  • date_sub(date1,interval d_value d_type):在date1上减去一个时间

image

image

  • datediff(date1,date2):两个日期差

image

  • day(date):返回日期的天

image

  • dayname(date):返回英文星期

image

  • dayofweek(date):返回星期(1-7),1为星期天

image

  • dayofyear(date):返回一年中的第几天

image

  • extract(interval_name from date):从date中提取日期的指定部分

image

  • makedate(year,day):返回年以及年中的第几天,生成日期串

image

  • maketime(hour,minute,second):生成时间串

image

  • monthname(date):英文月份名

image

  • now():当前时间

image

  • sec_to_time(seconds):秒数转成时间

image

  • str_to_date(string,format):字符串转成时间,以format格式显示

image

  • timediff(datetime1,datetime2):两个时间差

image

  • time_to_sec(time):时间转成秒数

image

  • week(date_time[,start_of_week]):第几周

image

  • year(datetime):返回指定日期的月份

image

  • dayofmonth(datetim):返回月的第几天

image

  • hour(datetime):返回小时

image

  • last_day(date):返回date的月的最后日期

image

  • microsecond(datetime):微妙

image

  • month(datetime):返回月

image

  • minute(datetime):返回分钟

image

posted @ 2020-01-28 09:47  郭小白  阅读(716)  评论(0编辑  收藏  举报