MySQL-常用函數

常用關鍵字

  • binary: 強制區分大小寫。我們知道MySQL是不區分大小寫的,我們可以使用binary關鍵字來強制MySQL區分大小寫
mysql> select username from user where username = 'laozhang';
+----------+
| username |
+----------+
| laozhang |
| laozhang |
| LAOZHANG |
+----------+
3 rows in set (0.00 sec)

mysql> select username from user where binary username = 'laozhang';
+----------+
| username |
+----------+
| laozhang |
| laozhang |
+----------+
2 rows in set (0.00 sec)
  • distinct: 最小化輸出,每個唯一的輸出記錄一次。若搜索多列數據,則組合輸出的唯一記錄一次,並且無需在每列中添加關鍵字distinct
mysql> select username from user;
+----------+
| username |
+----------+
| laozhang |
| laoyang  |
| laowang  |
| laohe    |
| laozhang |
| laoli    |
| laoliang |
| laoyang  |
+----------+
8 rows in set (0.00 sec)

mysql> select distinct username from user;
+----------+
| username |
+----------+
| laozhang |
| laoyang  |
| laowang  |
| laohe    |
| laoli    |
| laoliang |
+----------+
6 rows in set (0.00 sec)
  • interval: 間隔
# 2018-11-11加1個月
mysql> select "2018-11-11" + interval 1 month as date;
+------------+
| date       |
+------------+
| 2018-12-11 |
+------------+
1 row in set (0.01 sec)

mysql> select "2018-11-11" - interval 1 month;
+---------------------------------+
| "2018-11-11" - interval 1 month |
+---------------------------------+
| 2018-10-11                      |
+---------------------------------+
1 row in set (0.00 sec)

常用函數

  • version(): 獲取當前MySQL版本
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.18    |
+-----------+
1 row in set (0.00 sec)
  • user(): 獲取當前登錄用戶
mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
  • last_insert_id(): 獲取上一次插入得到的ID
mysql> insert into student(name, age) values("laoliang", 20);
Query OK, 1 row affected (0.01 sec)
 
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
|               10 |
+------------------+
1 row in set (0.00 sec)
  • coalesce(value, …): 返回列表中的第一個非空值,如果沒有非空值,則返回null
# 如果age爲空,則取score,若score也爲空,則返回1
mysql> select coalesce(age, score, 1) from student;
  • greatest(value1, value2, …): 使用兩個或多個參數,返回最大值,若參數中包含null,則返回null。使用如下:
mysql> select greatest(1, 2, 0, 4, 3);
+-------------------------+
| greatest(1, 2, 0, 4, 3) |
+-------------------------+
|                       4 |
+-------------------------+
1 row in set (0.00 sec)

mysql> select greatest(1, 2, 0, null, 3);
+----------------------------+
| greatest(1, 2, 0, null, 3) |
+----------------------------+
|                       NULL |
+----------------------------+
1 row in set (0.00 sec)
  • isnull(expr): 判斷expr是否爲null,爲null返回1,不爲空返回0,使用如下:
mysql> select isnull(1 + 1), isnull(1 / 0), isnull(null);
+---------------+---------------+--------------+
| isnull(1 + 1) | isnull(1 / 0) | isnull(null) |
+---------------+---------------+--------------+
|             0 |             1 |            1 |
+---------------+---------------+--------------+
1 row in set (0.00 sec)
  • interval(N, N1, N2, N3, …): 如果N < N1則返回0,N < N2返回1,N < N3則返回2,以此類推。使用如下:
mysql> select interval(1, 2, 3, 4, 5), interval(2, 2, 3, 4, 5), interval(3, 2, 3, 4, 5), interval(4, 2, 3, 4, 5);
+-------------------------+-------------------------+-------------------------+-------------------------+
| interval(1, 2, 3, 4, 5) | interval(2, 2, 3, 4, 5) | interval(3, 2, 3, 4, 5) | interval(4, 2, 3, 4, 5) |
+-------------------------+-------------------------+-------------------------+-------------------------+
|                       0 |                       1 |                       2 |                       3 |
+-------------------------+-------------------------+-------------------------+-------------------------+
1 row in set (0.01 sec)
  • least(value1, value2, …): 使用兩個或多個參數,返回最小值參數。如果有任何參數爲null,則結果爲null。使用如下:
mysql> select least(1, 0.1, 2, 4, 3);
+------------------------+
| least(1, 0.1, 2, 4, 3) |
+------------------------+
|                    0.1 |
+------------------------+
1 row in set (0.00 sec)

mysql> select least(1, 0.1, 2, 4, null);
+---------------------------+
| least(1, 0.1, 2, 4, null) |
+---------------------------+
|                      NULL |
+---------------------------+
1 row in set (0.00 sec)
  • concat(str1, str2, …): 返回參數連接所產生的字符串,如果參數包含null,則返回null。使用如下:
mysql> select concat(19.04, 'laozhang'), concat(19.04), concat('a', 'b', null, 'c');
+---------------------------+---------------+-----------------------------+
| concat(19.04, 'laozhang') | concat(19.04) | concat('a', 'b', null, 'c') |
+---------------------------+---------------+-----------------------------+
| 19.04laozhang             | 19.04         | NULL                        |
+---------------------------+---------------+-----------------------------+
1 row in set (0.00 sec)
  • concat_ws(separator, str1, str2, …): 一個特殊形式的concat,第一個參數爲分隔符。使用如下:
mysql> select concat_ws(",", 19.04, 'hhaha');
+--------------------------------+
| concat_ws(",", 19.04, 'hhaha') |
+--------------------------------+
| 19.04,hhaha                    |
+--------------------------------+
1 row in set (0.00 sec)
  • elt(n, str1, str2, …): 返回字符串列表中的第n個字符串,如n=1,則返回str1,如n=2,則返回str2,以此類推。使用如下:
mysql> select elt(1, 'a', 'c', 'd', 'b'), elt(2, 'a', 'c', 'd', 'b'), elt(0, 'a', 'c', 'd', 'b');
+----------------------------+----------------------------+----------------------------+
| elt(1, 'a', 'c', 'd', 'b') | elt(2, 'a', 'c', 'd', 'b') | elt(0, 'a', 'c', 'd', 'b') |
+----------------------------+----------------------------+----------------------------+
| a                          | c                          | NULL                       |
+----------------------------+----------------------------+----------------------------+
1 row in set (0.00 sec)
  • field(str, str1, str2, str3, str4, …): 如果str=str1,返回1,str=str2,返回2,以此類推;如果strnull,則返回0, 如果未找到相等的也等於0。使用如下:
mysql> select field('a', 'a', 'c', 'b'), field('b', 'a', 'c', 'b'), field('d', 'a', 'c', 'b'), field(null, 'a', 'c', 'b', null);
+---------------------------+---------------------------+---------------------------+----------------------------------+
| field('a', 'a', 'c', 'b') | field('b', 'a', 'c', 'b') | field('d', 'a', 'c', 'b') | field(null, 'a', 'c', 'b', null) |
+---------------------------+---------------------------+---------------------------+----------------------------------+
|                         1 |                         3 |                         0 |                                0 |
+---------------------------+---------------------------+---------------------------+----------------------------------+
1 row in set (0.00 sec)
  • find_in_set(str, strlist): 獲取str串在strlist字符串的位置,1爲起始位置,找不到返回0;strlist爲多個字符串以逗號隔開連接的字符串;如果str或者strlist中有一個爲空,則返回空。使用如下:
mysql> select find_in_set("a", "a,b,c"), find_in_set("d", "a,b,c"), find_in_set(null, "a,b,c");
+---------------------------+---------------------------+----------------------------+
| find_in_set("a", "a,b,c") | find_in_set("d", "a,b,c") | find_in_set(null, "a,b,c") |
+---------------------------+---------------------------+----------------------------+
|                         1 |                         0 |                       NULL |
+---------------------------+---------------------------+----------------------------+
1 row in set (0.00 sec)
  • format(x, d): 格式化字符串,返回一個字符串,d爲保留的小數位數。使用如下:
mysql> select format(19.04, 1), format(19.05, 1);
+------------------+------------------+
| format(19.04, 1) | format(19.05, 1) |
+------------------+------------------+
| 19.0             | 19.1             |
+------------------+------------------+
1 row in set (0.00 sec)
  • insert(str, pos, len, newstr): 返回字符串str, 在pos開始長度爲len的字符替換成爲newstr。如果pos不在字符串的長度內,則返回原始字符串;如果pos開始len長度中,不在字符串的長度內,則從位置替換字符串的其餘部分。使用如下:
mysql> select insert("123456", 2, 2, "what"), insert("123456", -1, 4, "what"), insert("123456", 2, 6, "what");
+--------------------------------+---------------------------------+--------------------------------+
| insert("123456", 2, 2, "what") | insert("123456", -1, 4, "what") | insert("123456", 2, 6, "what") |
+--------------------------------+---------------------------------+--------------------------------+
| 1what456                       | 123456                          | 1what                          |
+--------------------------------+---------------------------------+--------------------------------+
1 row in set (0.00 sec)
  • instr(str, substr): 返回substr字符串在str字符串中第一次出現的位置,不存在返回0。使用如下:
mysql> select instr('basketball', 'ball'), instr('football', 'basket');
+-----------------------------+-----------------------------+
| instr('basketball', 'ball') | instr('football', 'basket') |
+-----------------------------+-----------------------------+
|                           7 |                           0 |
+-----------------------------+-----------------------------+
1 row in set (0.00 sec)
  • lcase(str): 將str的小寫形式返回,與lower()作用一樣。使用如下:
mysql> select lcase('JDK'), lcase(''), lcase(null);
+--------------+-----------+-------------+
| lcase('JDK') | lcase('') | lcase(null) |
+--------------+-----------+-------------+
| jdk          |           | NULL        |
+--------------+-----------+-------------+
1 row in set (0.00 sec)
  • left(str, len): 在str字符串中從最左邊開始截取len個字符返回,strlennull,則返回null。使用如下:
mysql> select left("abcdefg", 2), left("abcdefg", -2), left("abcdefg", null), left(null, 2);
+--------------------+---------------------+-----------------------+---------------+
| left("abcdefg", 2) | left("abcdefg", -2) | left("abcdefg", null) | left(null, 2) |
+--------------------+---------------------+-----------------------+---------------+
| ab                 |                     | NULL                  | NULL          |
+--------------------+---------------------+-----------------------+---------------+
1 row in set (0.00 sec)
  • length(str): 獲取str字符串的長度,strnull則返回null,使用如下:
mysql> select length('abcdefg'), length(null), length(0);
+-------------------+--------------+-----------+
| length('abcdefg') | length(null) | length(0) |
+-------------------+--------------+-----------+
|                 7 |         NULL |         1 |
+-------------------+--------------+-----------+
1 row in set (0.01 sec)
  • locate(substr, str), locate(substr, str, pos): 第一種:獲取substrstr中第一次出現的位置;第二種:獲取substrstr中從pos位置開始第一次出現的位置。如果substr不存在,則返回0,如果substr活着strnull,則返回null。第一種方式功能等同於instr。使用如下:
mysql> select locate('asd', '123asd123asd'), locate('df', '123asd123asd'), locate(null, '123asd123asd'), locate('df', null), locate('asd', '123asd123asd', 11);
+-------------------------------+------------------------------+------------------------------+--------------------+-----------------------------------+
| locate('asd', '123asd123asd') | locate('df', '123asd123asd') | locate(null, '123asd123asd') | locate('df', null) | locate('asd', '123asd123asd', 11) |
+-------------------------------+------------------------------+------------------------------+--------------------+-----------------------------------+
|                             4 |                            0 |                         NULL |               NULL |                                 0 |
+-------------------------------+------------------------------+------------------------------+--------------------+-----------------------------------+
1 row in set (0.00 sec)
  • lower(str): 將str字符串的小寫形式返回,使用如下:
mysql> select lower('JDK'), lower(''), lower(null);
+--------------+-----------+-------------+
| lower('JDK') | lower('') | lower(null) |
+--------------+-----------+-------------+
| jdk          |           | NULL        |
+--------------+-----------+-------------+
1 row in set (0.00 sec)
  • ltrim(str): 去除字符串str左邊的空格後返回,使用如下:
mysql> select ltrim('   foot ball  ');
+-------------------------+
| ltrim('   foot ball  ') |
+-------------------------+
| foot ball               |
+-------------------------+
1 row in set (0.01 sec)
  • mid(str, pos, len): 字符串截取,從pos位置開始,截取len個長度,效果與substring()方法一樣。使用如下:
mysql> select mid('hello world', 1, 5), mid('hello world', 3, 6);
+--------------------------+--------------------------+
| mid('hello world', 1, 5) | mid('hello world', 3, 6) |
+--------------------------+--------------------------+
| hello                    | llo wo                   |
+--------------------------+--------------------------+
1 row in set (0.00 sec)
  • position(substr in str): 獲取substrstr字符串中第一次出現的位置。效果與locate()instr()方法一樣,使用如下:
mysql> select position('asd' in '123asd123asd'), position('df' in '123asd123asd'), position(null in '123asd123asd'), position('asd' in null);
+-----------------------------------+----------------------------------+----------------------------------+-------------------------+
| position('asd' in '123asd123asd') | position('df' in '123asd123asd') | position(null in '123asd123asd') | position('asd' in null) |
+-----------------------------------+----------------------------------+----------------------------------+-------------------------+
|                                 4 |                                0 |                             NULL |                    NULL |
+-----------------------------------+----------------------------------+----------------------------------+-------------------------+
1 row in set (0.00 sec)
  • repeat(str, count): 返回由str重複count次數的字符串組成的新字符串。如果count小於或等於0,將返回空字符串;strcountnull,則返回null,使用如下:
mysql> select repeat('mysql', 3), repeat('mysql', -1), repeat('mysql', 0), repeat(null, 2), repeat('mysql', null);
+--------------------+---------------------+--------------------+-----------------+-----------------------+
| repeat('mysql', 3) | repeat('mysql', -1) | repeat('mysql', 0) | repeat(null, 2) | repeat('mysql', null) |
+--------------------+---------------------+--------------------+-----------------+-----------------------+
| mysqlmysqlmysql    |                     |                    | NULL            | NULL                  |
+--------------------+---------------------+--------------------+-----------------+-----------------------+
1 row in set (0.01 sec)
  • replace(str, from_str, to_str): 將str字符串中的所有from_str替換成爲to_str後返回。如果from_str不在str字符串中存在,則原樣返回;如果strfrom_strto_str中有一個字符串爲null,則返回null。使用如下:
mysql> select replace('123asd123asd', 'asd', 'ggg'), replace('123asd123asd', '-1', '30'), replace(null, 'asd', 'ggg'), replace('123asd123asd', null, 'ggg'), replace('123asd123sad', 'asd', null);
+---------------------------------------+-------------------------------------+-----------------------------+--------------------------------------+--------------------------------------+
| replace('123asd123asd', 'asd', 'ggg') | replace('123asd123asd', '-1', '30') | replace(null, 'asd', 'ggg') | replace('123asd123asd', null, 'ggg') | replace('123asd123sad', 'asd', null) |
+---------------------------------------+-------------------------------------+-----------------------------+--------------------------------------+--------------------------------------+
| 123ggg123ggg                          | 123asd123asd                        | NULL                        | NULL                                 | NULL                                 |
+---------------------------------------+-------------------------------------+-----------------------------+--------------------------------------+--------------------------------------+
1 row in set (0.00 sec)
  • reverse(str): 反轉。使用如下:
mysql> select reverse('abc'), reverse('123');
+----------------+----------------+
| reverse('abc') | reverse('123') |
+----------------+----------------+
| cba            | 321            |
+----------------+----------------+
1 row in set (0.00 sec)
  • right(str, len): 返回str字符串中最右邊的len長度的字符。如果len不在str字符串的長度內,則返回空字符串;如果str或者countnull,則返回null。使用如下:
mysql> select right('football', 4), right('football', 0), right('football', -1), right('football', 10), right('football', null), right(null, 4);
+----------------------+----------------------+-----------------------+-----------------------+-------------------------+----------------+
| right('football', 4) | right('football', 0) | right('football', -1) | right('football', 10) | right('football', null) | right(null, 4) |
+----------------------+----------------------+-----------------------+-----------------------+-------------------------+----------------+
| ball                 |                      |                       | football              | NULL                    | NULL           |
+----------------------+----------------------+-----------------------+-----------------------+-------------------------+----------------+
1 row in set (0.00 sec)
  • rtrim(str): 去除str字符串右邊的空格而後返回,strnull則返回null。使用如下:
mysql> select rtrim('foot ball  '), rtrim(null);
+----------------------+-------------+
| rtrim('foot ball  ') | rtrim(null) |
+----------------------+-------------+
| foot ball            | NULL        |
+----------------------+-------------+
1 row in set (0.00 sec)
  • space(n): 返回n個空格,如果nnull則返回null。使用如下:
mysql> select space(5), space(null);
+----------+-------------+
| space(5) | space(null) |
+----------+-------------+
|          | NULL        |
+----------+-------------+
1 row in set (0.01 sec)
  • substring(str, pos), substring(str from pos), substring(str, pos, len), substring(str from pos for len): 字符串截取,如果len小於1,將會返回空字符串
    • substring(str, pos):在pos位置開始截取,到末尾
    • substring(str from pos):在pos位置開始截取,到末尾
    • substring(str, pos, len):在pos位置開始截取,截取len個長度
    • substring(str from pos for len):在pos位置開始截取,截取len個長度
mysql> select substring('abcdefg', 2), substring('abcdefg' from 2), substring('abcdefg', 2, 2), substring('abcdefg' from 2 for 2);
+-------------------------+-----------------------------+----------------------------+-----------------------------------+
| substring('abcdefg', 2) | substring('abcdefg' from 2) | substring('abcdefg', 2, 2) | substring('abcdefg' from 2 for 2) |
+-------------------------+-----------------------------+----------------------------+-----------------------------------+
| bcdefg                  | bcdefg                      | bc                         | bc                                |
+-------------------------+-----------------------------+----------------------------+-----------------------------------+
1 row in set (0.00 sec)
  • substr(str, pos), substr(str from pos), substr(str, pos, len), substr(str from pos for len):字符串截取,效果與substring()一樣
  • substring_index(str, delim, count)str字符串中delim出現count次位置開始截取,如果count爲正數,往左邊截取;如果爲負數,往右邊開始截取;如果爲零,則返回空字符串。使用如下:
mysql> select substring_index('www.baidu.com', '.', 2), substring_index('www.baidu.com', '.', '-2'), substring_index('www.baidu.com', '.', 0);
+------------------------------------------+---------------------------------------------+------------------------------------------+
| substring_index('www.baidu.com', '.', 2) | substring_index('www.baidu.com', '.', '-2') | substring_index('www.baidu.com', '.', 0) |
+------------------------------------------+---------------------------------------------+------------------------------------------+
| www.baidu                                | baidu.com                                   |                                          |
+------------------------------------------+---------------------------------------------+------------------------------------------+
1 row in set (0.00 sec)
  • trim(str), trim(remstr from str), trim(leading remstr from str), trim(trailing remstr from str), trim(both remstr from str): 去除空格或指定字符串
    • trim(str):去除str字符串中左右兩邊的空格
    • trim(remstr from str):去除str字符串中左右兩邊的字符串remstr
    • trim(leading remstr from str):去除str字符串中最左邊的字符串remstr
    • trim(trailing remstr from str):去除str字符串中最右邊的字符串remstr
    • trim(both remstr from str):去除str字符串中左右兩邊的字符串remstr。效果與trim(remstr from str)一樣
msyql> select trim(' a b '), trim('123' from '123a123a123'), trim(leading '123' from '123a123a123'), trim(trailing '123' from '123a123a123'), trim(both '123' from '123a123a123');
+---------------+--------------------------------+----------------------------------------+-----------------------------------------+-------------------------------------+
| trim(' a b ') | trim('123' from '123a123a123') | trim(leading '123' from '123a123a123') | trim(trailing '123' from '123a123a123') | trim(both '123' from '123a123a123') |
+---------------+--------------------------------+----------------------------------------+-----------------------------------------+-------------------------------------+
| a b           | a123a                          | a123a123                               | 123a123a                                | a123a                               |
+---------------+--------------------------------+----------------------------------------+-----------------------------------------+-------------------------------------+
1 row in set (0.00 sec)
  • ucase(str): 將str字符串的大寫形式返回,使用如下:
mysql> select ucase('asd');
+--------------+
| ucase('asd') |
+--------------+
| ASD          |
+--------------+
1 row in set (0.00 sec)
  • upper(str): 將str字符串的大寫形式返回,使用如下
mysql> select upper('asd');
+--------------+
| upper('asd') |
+--------------+
| ASD          |
+--------------+
1 row in set (0.00 sec)
  • strcmp(expr1, expr2): 如果expr1expr2相同,則返回0;如果expr1expr2小,則返回-1;如果expr1expr2大,則返回1。使用如下:
mysql> select strcmp('0', '0'), strcmp('test', 'test'), strcmp('0', '1'), strcmp('test', 'test1'), strcmp('1', '0'), strcmp('test1', 'test');
+------------------+------------------------+------------------+-------------------------+------------------+-------------------------+
| strcmp('0', '0') | strcmp('test', 'test') | strcmp('0', '1') | strcmp('test', 'test1') | strcmp('1', '0') | strcmp('test1', 'test') |
+------------------+------------------------+------------------+-------------------------+------------------+-------------------------+
|                0 |                      0 |               -1 |                      -1 |                1 |                       1 |
+------------------+------------------------+------------------+-------------------------+------------------+-------------------------+
1 row in set (0.00 sec)
  • abs(x): 返回x的絕對值,使用如下:
mysql> select abs(-2), abs(-32);
+---------+----------+
| abs(-2) | abs(-32) |
+---------+----------+
|       2 |       32 |
+---------+----------+
1 row in set (0.00 sec)
  • ceiling(x): 返回不小於x的最小整數
mysql> select ceiling(1.32), ceiling(-1.32);
+---------------+----------------+
| ceiling(1.32) | ceiling(-1.32) |
+---------------+----------------+
|             2 |             -1 |
+---------------+----------------+
1 row in set (0.00 sec)
  • ceil(x): 返回不小於x的最小整數,效果與ceiling()方法一樣
  • mod(n, m), n % m, n mod m: 取模運算
mysql> select mod(9, 2), 9 % 2, 9 mod 2;
+-----------+-------+---------+
| mod(9, 2) | 9 % 2 | 9 mod 2 |
+-----------+-------+---------+
|         1 |     1 |       1 |
+-----------+-------+---------+
1 row in set (0.00 sec)
  • rand(): 返回一個0 <= value < 1的隨機浮點數。使用如下:
mysql> select rand(), rand();
+--------------------+-------------------+
| rand()             | rand()            |
+--------------------+-------------------+
| 0.2508203557234447 | 0.608450261511328 |
+--------------------+-------------------+
1 row in set (0.00 sec)
  • round(x), round(x, d): 四捨五入運算
    • round(x):保留整數位
    • round(x, d):將x保留d位小數
mysql> select round(1.4), round(1.5), round(1.24, 1), round(1.25, 1), round(1.25, 0);
+------------+------------+----------------+----------------+----------------+
| round(1.4) | round(1.5) | round(1.24, 1) | round(1.25, 1) | round(1.25, 0) |
+------------+------------+----------------+----------------+----------------+
|          1 |          2 |            1.2 |            1.3 |              1 |
+------------+------------+----------------+----------------+----------------+
1 row in set (0.00 sec)
  • sqrt(x): 返回x的開平方值。使用如下:
mysql> select sqrt(4), sqrt(9), sqrt(2), sqrt(-16);
+---------+---------+--------------------+-----------+
| sqrt(4) | sqrt(9) | sqrt(2)            | sqrt(-16) |
+---------+---------+--------------------+-----------+
|       2 |       3 | 1.4142135623730951 |      NULL |
+---------+---------+--------------------+-----------+
1 row in set (0.00 sec)
  • truncate(x, d): 截斷x到小數點後d位。使用如下:
mysql> select truncate(1.23, 1), truncate(1.25, 1);
+-------------------+-------------------+
| truncate(1.23, 1) | truncate(1.25, 1) |
+-------------------+-------------------+
|               1.2 |               1.2 |
+-------------------+-------------------+
1 row in set (0.01 sec)

常用屬性

  • current_date: 獲取當前日期
mysql> select current_date;
+--------------+
| current_date |
+--------------+
| 2018-11-10   |
+--------------+
1 row in set (0.00 sec)
  • current_time: 獲取當前時間
mysql> select current_time;
+--------------+
| current_time |
+--------------+
| 10:22:15     |
+--------------+
1 row in set (0.00 sec)
  • localtime: 獲取當前日期時間
mysql> select localtime;
+---------------------+
| localtime           |
+---------------------+
| 2019-01-02 13:41:47 |
+---------------------+
1 row in set (0.01 sec)
  • localtimestamp: 獲取當前日期時間,作用與localtime一樣
mysql> select localtimestamp;
+---------------------+
| localtimestamp      |
+---------------------+
| 2019-01-02 13:42:11 |
+---------------------+
1 row in set (0.00 sec)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章