mysql 常用几个函数简单实例演示

instr()/lower()/replace()/substr()/las_day:

– 1.用 instr() 函数查找w在hello world短语中出现的字符位置 **
select instr(‘hello word’,‘w’);

– 2.用 lower() 函数将HELLO转换为小写,用 upper() 函数将world转换为大写,并用 concat() 函数将两部分连接在一起 *
select concat(lower(‘HELLO’) ,upper(‘Word’)) ;

– 3.用 replace() 函数将 hello earth 短语中的 earth 替换为 world *
select replace(‘hello earth’ ,‘earth’ ,‘world’);

– 4.用 substr() 函数提取 hello world 短语中 llo w 部分的内容 **
select substr(‘hello world’,3,5);

– 5.用last_day函数返回当前月份的最后一天的日期(当前日期是变量now) **
select last_day(now());

– 6.用date_format将文本’2019-01-01’转换为正确的日期型日期 ***
select date_format(‘2019-01-01’,‘%Y-%m-%d’);

– 7.用cast函数将emp表中的empno数字转换为文本型 ***
select cast(empno as char(4)) from emp;

文章出处https://zhuanlan.zhihu.com/p/73199108

posted @ 2020-09-06 13:42  勤奋的蓝猫  阅读(3)  评论(0编辑  收藏  举报  来源