zoukankan      html  css  js  c++  java
  • mysql

    处理字符:

    1:concat('aaa', 'bbb', 'ccc')

    拼接字符串,oracle也有这个方法不过只能拼接2个,而且一般用 ‘||’ 。。

    mysql中‘||’表示或。相当于or

    2:ifnull(name,'aaa')   

    当name = null时,返回'aaa'

    3.upper('aaa'),lower('AAA')

    变为大写,小写

    4.substr

    substr('abc张三', 1, 4) = abc张

    从第一个字符开始,截取4位

    substr('abc张三', 4) = 张三

    从第4个字符开始截取到最后(字符包括汉字,每个汉字是一个字符)

    mysq的lindex是从1开始- -,比较搞。。。

    5.length

    length('abc张三')  = 9

    length是字节长度,mysql汉字等于 3个字节,字母和符号时1个。

    也挺搞的 - -

    6.instr

    instr('aaa', 'abcaaabbbcccaaa') = 4

    返回子串在父串第一次出现的位置,没有返回0

    7.trim

    trim('a' from 'aaabbbaaabbbaaa') = 'bbbaaabbb'

    去掉前后的a

    trim('   aaa   ') = 'aaa'

    去掉前后空格

    8.lpad,rpad

    lpad('张三', 5, 'aaa') = aaa张三

    左边填充aaa直到字符串有5个字符

    rpad('张三', 8, 'ab') = 张三ababab

    右边填充ab直到字符串有8个字符。 

    9.replace

    replace('张三李四王五', '王五', '赵六') = 张三李四赵六

    替换

    数字方法

    1.round

    round(1.23) = 1

    四舍五入

    round(1.23, 1) = 1.2

    四舍五入留1位

    ceil

    向上取整

    cell(1.6) = 2

    ceil(-1.6) = -1;

    floor

    向下取整

    truncate

    截断

    2.mod

    mod(10,3)  = 10%3 = 1

    mod(-10,-3) = -1

    3.abs

    abs(-111) = -1

    abs('aaa') = 0

    取绝对值,不是数字返回0

    日期:

    1. now()

    当前时间

    2.curdate

    当前日期,不包含时间

    3.currenttime

    当前时间

    4.year()

    year(now()) = 2019

    year('2019-05-26') = 2019

    year('1990/05/26') = 1990

    获取括号中日期的年份,日期格式的字符串也可以

    month,day,hour等同理

    month('2019-05-26') = 5

    monthname('2019-05-26') = May

    5. str_to_date()

     把字符串按照后面的格式解析变为时间,错误返回null

    %Y = 4位年份, %y = 2位年份

    %m = 月(01,02), %c = 月(1,2) , 这两个貌似测试的时候混了也没事。。。

    %d = 日

    %H = 24制小时, %h = 12制小时     如果%h 而小时是20不会自动转化,会错误返回null

    %i = 分

    %s = 秒 

    6.date_format

    7。时间差

    datediff (天数差)

    select datediff(now(),'1990-05-26');

    timestampdiff ( 单位, date1, date2)

    SELECT TIMESTAMPDIFF(YEAR, '1990-05-26', NOW()),
    TIMESTAMPDIFF(MONTH, '1990-05-26', NOW()),
    TIMESTAMPDIFF(DAY, '1990-05-26', NOW()),
    TIMESTAMPDIFF(HOUR, '1990-05-26', NOW()),
    TIMESTAMPDIFF(MINUTE, '1990-05-26', NOW()),
    TIMESTAMPDIFF(SECOND, '1990-05-26', NOW());

    前面的时间 - 后面的时间,结果可以为负数

    数据库方法:

    1.version()

    版本号

    2.database()

    显示当前数据库名

    3.user()

    当前用户

    流程控制函数:

    1.if

    if(条件,条件为true时,条件为false时)

    2.case

     case 参数

    when 值1 then 结果1,

    when 值2 then 结果2,

    ...

    else 其他情况结果

    end 

     case

    when 条件1 then 结果1,

    when 条件2 then 结果2,

    ...

    else 其他情况结果

    end 

    与标题无关的笔记。。。

    排序

    order by name desc, id asc 

    按名字从大到小排列(字符串从头开始依次比较asc码),name相同时,按id从小到大排列

  • 相关阅读:
    [ios] 响应上下左右滑动手势
    [ios]字符串转化成NSDate类型 计算与当前时间的相差 月数 天数 【转】
    [ios] NSSet,NSMutableSet[zhuan]
    [ios] 如何让xcode自动检查内存泄露 【转】
    iOS 使用Quartz 2D画虚线 【转】
    [ios]设置表格单元格交替背景 【转】
    [ios] IOS文件操作的两种方式:NSFileManager操作和流操作【转】
    [ios] 自定义UIAlertView样式,实现可替换背景和按钮 【转】
    [ios]上传应用程序到app store 【转】
    [ios] iOS中arc的设置与使用
  • 原文地址:https://www.cnblogs.com/clamp7724/p/11781168.html
Copyright © 2011-2022 走看看