存儲過程-第三課(函數)

一、字符串

1)charset(str)返回字符串字符集

       concat(str,...)鏈接字符串

2)instr(str,substr) 返回substr在str第一次出現索引

    lcase(str) 轉成小寫

3)left(str,lenth)截取str左數length個字符

      length(str)返回str的長度

4)load_file(file_path)從文件讀取數據

      locate(substr,str[,start_postion])同instr,但是可以指定開始位置

5)lpad(str,length,pad)重複用pad加載str前,知道達到length長度

      ltrim(str)去除str左邊的空格

6)repeat(str,count)重複str count次

      replace(str,search,replace)將str中search替換成replace

7)rpad(str,length,pad)向str後追加pad直到長度爲length

      rtrim(str)去掉str後面的空格

8)strcmp(str1,str2)比較str1和str2大小

      substring(str,position[,length})截取strposition後位置的length長度

注意:mysql處理字符串是,默認第一個字符的下標爲1,即參數postion大於等於1.

9)trim(both|leading|trailing  padding  FROM str) 去除str兩側或頭部或尾部的padding

      ucase(str)將str轉成大寫

10)right(str,length) 後面截取length長度

      space(count)生成count空格

二、數字類型函數

1)abs(num)絕對值

       bin(num)十進制轉2進制

       ceiling(num)向上取整

       conv(num,from_n,to_n)將num從from_n進制轉to_n進制

       floor(num)向下取整

2)format(num,2)保留小數位數

      hex(num)num的十六進制

      least(num1,num2,....)取最小值

      mod(num,denominator)取餘

3)power(num,2)求num的指數

      rand(num)求num以內的隨機數

      round(num,num2)四捨五入,num2標識小數位數

      sign(num)返回num的符號

三、日期函數

1)addtime(date,time_interval) 將相同格式time_interval添加到date

       current_date()當前日期

       current_time()當前時間

       current_timestamp()當前時間戳

2)date(datetime)返回datetime的日期部分

    date_add(datetime,INTERVAL  expr   type)給datetime的type類型加expr

Type 值

 
MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
SECOND_MICROSECOND
MINUTE_MICROSECOND
MINUTE_SECOND
HOUR_MICROSECOND
HOUR_SECOND
HOUR_MINUTE
DAY_MICROSECOND
DAY_SECOND
DAY_MINUTE
DAY_HOUR
YEAR_MONTH

3)date_format(datetime,format)將datetime格式化成format


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章