• MariaDB Text,Time,Numeric Manipulation Function


    MariaDB Text,Time,Numeric Manipulation Function

    字符操作函数

    Commonly Used Text-Manipulation Functions

    ---------------------------------------------------

    Function    Description

    ---------------------------------------------------

    Left()      Returns characters from left of string

    Length()    Returns the length of a string

    Locate()    Finds a substring within a string

    Lower()     Converts string to lowercase

    LTrim()     Trims white space from left of string

    Right()     Returns characters from right of string

    RTrim()     Trims white space from right of string

    Soundex()   Returns a string’s SOUNDEX value

    SubString() Returns characters from within a string

    Upper()     Converts string to uppercase

    ---------------------------------------------------



    (jlive)[crashcourse]>SELECT vend_name, UPPER(vend_name) AS vend_name_uppercase FROM vendors ORDER BY vend_name;

    +----------------+---------------------+

    | vend_name      | vend_name_uppercase |

    +----------------+---------------------+

    | ACME           | ACME                |

    | Anvils R Us    | ANVILS R US         |

    | Furball Inc.   | FURBALL INC.        |

    | Jet Set        | JET SET             |

    | Jouets Et Ours | JOUETS ET OURS      |

    | LT Supplies    | LT SUPPLIES         |

    +----------------+---------------------+

    6 rows in set (0.00 sec)


    (jlive)[crashcourse]>SELECT cust_name, cust_contact FROM customers WHERE cust_contact = 'Y. Lie';

    Empty set (0.00 sec)


    (jlive)[crashcourse]>SELECT cust_name, cust_contact FROM customers WHERE Soundex(cust_contact) = Soundex('Y Lie');

    +-------------+--------------+

    | cust_name   | cust_contact |

    +-------------+--------------+

    | Coyote Inc. | Y Lee        |

    +-------------+--------------+

    1 row in set (0.00 sec)

    “听起来”像,就匹配


    时间操作函数

    提示:5.3以后的版本支持microseconds

    Commonly Used Date and Time Manipulation Functions

    -------------------------------------------------------

    Function Description

    -------------------------------------------------------

    AddDate() Add to a date (days, weeks, and so on)

    AddTime() Add to a time (hours, minutes, and so on)

    CurDate() Returns the current date

    CurTime() Returns the current time

    Date() Returns the date portion of a date time

    DateDiff() Calculates the difference between two dates

    Date_Add() Highly flexible date arithmetic function

    Date_Format() Returns a formatted date or time string

    Day() Returns the day portion of a date

    DayOfWeek() Returns the day of week for a date

    Hour() Returns the hour portion of a time

    Minute() Returns the minute portion of a time

    Month() Returns the month portion of a date

    Now() Returns the current date and time

    Second() Returns the second portion of a time

    Time() Returns the time portion of a date time

    Year() Returns the year portion of a date

     

    -------------------------------------------------------



    (jlive)[crashcourse]>SELECT order_date,cust_id,order_num FROM orders WHERE order_date = '2011-09-01';

    +---------------------+---------+-----------+

    | order_date          | cust_id | order_num |

    +---------------------+---------+-----------+

    | 2011-09-01 00:00:00 |   10001 |     20005 |

    +---------------------+---------+-----------+

    1 row in set (0.00 sec)

    以上判断非常不安全,这一天的记录可能非常多


    (jlive)[crashcourse]>SELECT order_date,cust_id,order_num FROM orders WHERE Date(order_date) = '2011-09-01';

    +---------------------+---------+-----------+

    | order_date          | cust_id | order_num |

    +---------------------+---------+-----------+

    | 2011-09-01 00:00:00 |   10001 |     20005 |

    +---------------------+---------+-----------+

    1 row in set (0.16 sec)

    需要用Date()函数重新格式化


    (jlive)[crashcourse]>SELECT order_date,cust_id,order_num FROM orders WHERE Date(order_date) BETWEEN '2011-09-01' AND '2011-09-30';

    +---------------------+---------+-----------+

    | order_date          | cust_id | order_num |

    +---------------------+---------+-----------+

    | 2011-09-01 00:00:00 |   10001 |     20005 |

    | 2011-09-12 00:00:00 |   10003 |     20006 |

    | 2011-09-30 00:00:00 |   10004 |     20007 |

    +---------------------+---------+-----------+

     

    3 rows in set (0.15 sec)

    上面虽然查出了2011年9月的数据但需要人为的计算该年该月份的起点和终点,如果碰到二月这个特殊的月份就会比较费力


    (jlive)[crashcourse]>SELECT order_date,cust_id,order_num FROM orders WHERE Year(order_date) = 2011 AND Month(order_date) = 9;

    +---------------------+---------+-----------+

    | order_date          | cust_id | order_num |

    +---------------------+---------+-----------+

    | 2011-09-01 00:00:00 |   10001 |     20005 |

    | 2011-09-12 00:00:00 |   10003 |     20006 |

    | 2011-09-30 00:00:00 |   10004 |     20007 |

    +---------------------+---------+-----------+

     

    3 rows in set (0.00 sec)

    全部交给MariaDB自己去解读


    Numeric函数

    -------------------------------------------------------------------

    Function Description

    -------------------------------------------------------------------

    Abs() Returns a number’s absolute value

    Cos() Returns the trigonometric cosine of a specified angle

    Exp() Returns the exponential value of a specific number

    Mod() Returns the remainder of a division operation

    Pi() Returns the value of pi

    Rand() Returns a random number

    Sin() Returns the trigonometric sine of a specified angle

    Sqrt() Returns the square root of a specified number

    Tan() Returns the trigonometric tangent of a specified angle

     

    -------------------------------------------------------------------

  • 相关阅读:
    OCP-052考试题库汇总(29)-CUUG内部解答版
    OCP-052考试题库汇总(28)-CUUG内部解答版
    OCP-052考试题库汇总(27)-CUUG内部解答版
    OCP-052考试题库汇总(26)-CUUG内部解答版
    OCP-052考试题库汇总(25)-CUUG内部解答版
    OCP-052考试题库汇总(24)-CUUG内部解答版
    007 线程的join方法
    006 线程休眠
    005 线程打断---完成线程的终结
    004 守护线程
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814190.html
Copyright © 2020-2023  润新知