select concat('CDA','数据', '分析'); -- CDA数据分析
select concat('CDA',null, '分析'); -- NULL
select instr('CDA', 'A'); -- 3
select instr('CDA', '数据分析'); -- 0
select left('CDA数据分析', 3); -- CDA 返回字符串str的左端len个字符
select right('CDA数据分析', 4); -- 数据分析 返回字符串str的右端len个字符
select mid('CDA数据分析', 4,2); -- 数据
select substring('CDA数据分析', 4,2); -- 数据
select ltrim(' CDA数据分析'); -- 返回删除了左空格的字符串str
select rtrim('CDA数据分析 '); -- 返回删除了右空格的字符串str
select trim(' CDA数据分析 '); -- 返回删除了两边空格的字符串str
select replace('CDA数据分析', 'CDA', 'cda'); -- cda数据分析
select repeat('CDA', 3); -- CDACDACDA
select reverse('CDA'); -- ADC
select upper('cda'); -- CDA
select lower('CDA'); -- cda
select abs(-32); -- 32
select floor(1.23); -- 1 返回不大于n的最大整数值
select ceiling(1.23); -- 2 返回不小于n的最小整数值
select round(1.58); -- 返回n的四舍五入值,保留d位小数
select rand(); -- 返回在范围0到1.0内的随机浮点值(数字n作为初始)
select rand(2);
select date('20200101'); -- 2020-01-01
select week('2019-01-01'); -- 返回指定日期是一年中的第几周
select month('2020-01-01'); -- 1
select quarter('2020-01-01'); -- 1
select year('20-01-01'); -- 2020
select date_add("2020-01-01",interval 1 day); -- 2020-01-02
select date_sub("2020-01-01", interval 1 day); -- 2019-12-31 从日期减去指定的时间间隔
select date_format('20-01-01 12:00:00','%Y-%m-%d'); -- 2020-01-01
mysql- 常用函数(1)
最新推荐文章于 2024-07-20 19:58:01 发布