• mysql-基本函数


    一、函数

      SQL支持利用函数来处理数据,函数一般都放在数据上执行,给数据转换和处理带来方便。

      1、Mysql支持用于处理文本串(如删除或填充值转换值为大小写)的文本函数。

      2、支持用于在数字上进行算术操作(如返回绝对值,进行运算)

      3、支持用于处理日期和时间值并从这些值中提取特定成分的日期和时间函数。

      4、返回DBMS正使用的特殊信息的系统函数。

    二、文本处理函数

      常用的文本处理函数,如下

      left()    返回串左边的字符

      length()    返回串的长度

      locate()     找到串的一个子串

      lower()      将串转换为小写

      ltrim()     去掉串左边的空格

      right()     返回串右边的字符

      rtrim()     去掉串右边的空格

      soundex()  返回穿的SOUNDEX值

      substring()  返回子串的字符

      upper    将串转换为大写

      

      其中soundex()函数是一个将任何文本串转换为描述其语音表示的字母数字模式的算法。它考虑了类似发音字符和音节,使得能对串进行发音比较而不是字母比较

      select cust_name,cust_contact from customers where cust_contact='Y.Lie';//无返回

      select cust_name,cust_contact from customers where soundex(cust_contact)=soundex('Y.Lie');//返回Y.lee

    二、日期和时间处理函数

      Mysql规定日期必须以yyyy-mm-dd格式出现。因此如下:

      select cust_id,order_num from orders where order_date = '2005-09-01';

      但是以上语句并不安全,我们需要使用mysql将给出的日期与列中的日期部分进行比较,而不是将给出的日期和整个列值进行比较。如下:

      select cust_id,order_num from orders where Date(order_date)='2005-09-01';//仅需要日期

      但是如果你需要检索出2005年9月下的所有订单,我们一般如下:

      select cust_id,order_num from orders where Year(order_date) =2005 and Month(order_date)=9;

      有关日期时间的函数如下:

      

      

    四、数字处理函数:它仅能处理数据

      

  • 相关阅读:
    202. Happy Number
    198. House Robber
    191. Number of 1 Bits
    190. Reverse Bits
    189. Rotate Array
    172. Factorial Trailing Zeroes
    171. Excel Sheet Column Number
    [leetcode]Single Number II
    [leetcode]Single Number
    [leetcode]Clone Graph
  • 原文地址:https://www.cnblogs.com/television/p/8350260.html
Copyright © 2020-2023  润新知