####官網最全的函數總結
一、常用函數
1. 數學運算
運算符 | 意義 | 使用 |
---|---|---|
1.abs() | 絕對值 | abs(-1) 輸出 1 |
2.ceiling() | 向上取整 | ceiling(9.4) 爲 10 |
3.floor() | 向下取整 | floor(9.4)爲 9 |
4.rand() | 返回一個0-1的隨機數字 | rand() = 0.2808596950777431 |
5.sign() | 判斷數字符號 | sign(-2) 爲-1, |
2.字符串函數
運算符 | 意義 | 使用 |
---|---|---|
1.char_length() | 字符串長度 | char_length(“hello”) 爲 5 |
2. concat() | 合併字符串 | concat(“he”,“llo”) 爲 hello |
3. insert() | 替換位置字符串 | SELECTINSERT(“hello”,2,4,“i”) 爲 hi(注意:這裏不是索引) |
4. replace() | 替換指定字符串 | replace(“hello”,“ello”,“i”) 爲 hi |
5. lower() | 全部小寫 | lower(“Hello”) 爲 hello |
6. upper() | 全部大寫 | lower(“Hello”) 爲 HELLO |
7. substr() | 返回位置的字符串 | substr(“hello”,2,3)源字符串,開始位置,長度 返回爲 ell |
8. instr() | 返回開始出現的位置(不是索引!) | instr(“hello”,“l”)爲3 |
9. reverse() | 反轉字符串 | reverse(“你好”) 爲 好你 |
3.時間和日期函數
3.1獲取時間和日期.
運算符 | 意義 | 使用 |
---|---|---|
1. current_time() | 當前時間 | current_time()爲 18:29:54 |
2. current_date() | 當前的日期 | current_date() 爲 2020-05-24 |
3. now() | 當前時間(等於日期date+時間time) | now() 爲 2020-05-24 18:33:52 |
4. localtime() | 本地時間(和 now一致) | 2020-05-24 18:41:07 |
5. sysdate() | 系統時間(和now()一致) | 2020-05-24 18:41:07 |
獲取需要的指定字段
運算符 | 意義 | 使用 |
---|---|---|
year(date) | 獲取日期的年份 | year(now()) 爲 2020 |
month(date) | 獲取月份 | month(now() )爲 5 |
day(date) | 天 | day(now()) 爲24 |
hour() | 小時 | hour(now()) 爲 18 |
minute() | 分 | minute(now()) 爲39 |
second() | 秒 | second(now()) 爲 42 |
4.系統函數
運算符 | 意義 | 使用 |
---|---|---|
1. system_user() | 系統用戶 | root@localhost |
2. user() | 用戶 | root@localhost |
3. version() | 系統版本 | 5.7.30 |