zoukankan      html  css  js  c++  java
  • mysql内置函数

    一、字符串函数

        1.concat(s1,s2....sn):把传入的参数连接成一个字符串;

        2.insert(str,x,y,str):从str的x位置开始,替换y长度的字符串为str,select insert('abcdefg',2,3,'hello');
        3.lower(str),upper(str):将字符串转换为大写,小写;
        4.left(str,x) right(str,x) 返回str左边(右边)x个字符,x为null则返回null;
        5.lpad(str,n,pad) rpad(str,n,pad)  用pad对字符串str从最左边(右边)进行填充,直到总长度达到n ; select name,lpad(name,10,'#'),rpad(name,10,'(') from cats;

        6.trim(),ltrim(),rtrim()去掉两边,左边,右边空格; select concat('1',trim('   abc   '),'2'),concat('1',ltrim('   abc   '),'2'),concat ('1',rtrim('   abc   '),'2')G;  

        7.replace(str,a,b) 在字符串str中用字符串b替换所有的字符串a;
        8.strcmp(s1,s2):如果S1比S2小,返回-1;如果S1比S2大则返回1;如果相等则返回0;

        9.substring(str,x,y) 返回字符串str中从位置x起,长度为y的子字符串;

    二、数值函数
        abs(x):返回绝对值;
        ceil(x):返回大于x的最小整数;
        floor(x):返回小于x的最大整数;
        mod(x,y):返回x与y的模;
        rand():返回0-1之间的随机数   select round(rand()*100);
        round(x,y):返回参数x的y位小数的四舍五入结果;
        truncate(x,y):返回数字x截断为y位小数的结果;

    三、日期函数
            curdate() curtime() now(); 

            select curdate();

            select unix_timestamp(now());
            select from_unixtime(1331110656);
            select week(now()),year(now());
            select hour(curtime()),minute(curtime());
            select monthname(now());
            select date_format(now(),"%Y-%m-%d %H:%i:%s");

            date_add(xxx,interval x day);

            data_sub(xxx,interva; x day);

  • 相关阅读:
    maven加载jar包配置
    JavaScript基础博客
    angularjs1 实现地图添加自定义控件(搜索功能)及事件
    AngularJS之Directive,scope,$parse
    HTML5 File详解
    angularjs上传图片
    input上传按钮美化
    AngularJs表单验证
    作用域与闭包
    理解JavaScript中的作用域和上下文
  • 原文地址:https://www.cnblogs.com/onlysun/p/4508663.html
Copyright © 2011-2022 走看看