wnnstudy

函数

  ①转小写:lower()

  示例:select lower(ename) from emp;

  ②转大写:upper()

  示例:select * from emp where job=upper(\'manager\');

  ③截取字符串:substr(要截取的字段,开始位置(从1开始),要截取的长度)

  示例:select substr(applabel,1,4) from appconfig;

  ④获取字段长度:length()

  示例:select length(appid) from appconfig;

  ⑤去除首尾空格,不包含中间的空格

  示例:select * from emp where job=trim(upper(\'manager  \'));

  ⑥将字符串转为日期:str_to_date(字符串,匹配格式)

  示例:select * from emp where HIREDATE=str_to_date(\'1981-02-20\',\'%Y-%m-%d\');

  ⑦获取当前日期:now()

 

 

   ⑧千分位:format(需要插入千分位的字段,位数)

  示例:select empno, ename, Format(sal, 2) from emp;

  ⑨四舍五入:round()

   示例:select round(123.56);

  ⑩生成随机数:rand()

  示例:select rand();

  ①①case..when..then..else..then..end

  示例:如果job为MANAGERG薪水上涨10%,如果job为SALESMAN工资上涨50%

    select empno, ename, job, sal, case job when \'MANAGER\' then sal*1.1 when \'SALESMAN\' then sal*1.5 end as newsal from emp;

  ①②ifnull()

  示例:select ifnull(comm,0) from emp;

  如果comm为空,则设置为0

 

分类:

技术点:

相关文章:

  • 2021-12-06
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2021-12-08
  • 2021-12-13
  • 2022-12-23
  • 2021-05-17
猜你喜欢
  • 2020-06-06
  • 2021-10-17
  • 2021-06-07
  • 2020-05-14
  • 2022-12-23
相关资源
相似解决方案