mysql学习(十二)内置函数

常用的内置函数,常用select\

  • 字符串函数
  1. contat('' , '', .....) //连接字符串

  select concat(name, ' age is ', age) from persons;

  1. insert(a, 2, 3, insert) //将字符a的第2个位置开始,3个字符替换为insert
    1. mysql> select name, insert(name, 2, 3, 'hello') from persons;
      +------------+-----------------------------+
      | name | insert(name, 2, 3, 'hello') |
      +------------+-----------------------------+
      | kaily_zhou | khelloy_zhou |
      | zhangsan | zhellogsan |
      +------------+-----------------------------+
      2 rows in set (0.00 sec)

  2. upper() / lower()大小写转换  

    select upper("hello");

    select lower("HELLO");

  1. left('', 2) /right('', 3)  

    select left('hello', 2), right('hello', 3); //返回字符串的左边右边几个字符

  1. lpad(name, 10, pa), rpad(name, 10, pa); //为了凑够10个字符,在字符串左边或者右边添加pa

mysql> select name, lpad(name, 20, '#'), rpad(name, 20, '@') from persons;
+------------+----------------------+----------------------+
| name | lpad(name, 20, '#') | rpad(name, 20, '@') |
+------------+----------------------+----------------------+
| kaily_zhou | ##########kaily_zhou | kaily_zhou@@@@@@@@@@ |
| zhangsan | ############zhangsan | zhangsan@@@@@@@@@@@@ |
+------------+----------------------+----------------------+
2 rows in set (0.00 sec)

  

  • 数值函数
  • 日期函数
上一篇:scrapy项目5:爬取ajax形式加载的数据,并用ImagePipeline保存图片


下一篇:Python网络爬虫_爬取Ajax动态加载和翻页时url不变的网页