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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM