mysql 經常使用幾個函數簡單實例演示

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

-- 1.用 instr() 函數查找w在hello world短語中出現的字符位置 **
select instr('hello word','w'); 函數

-- 2.用 lower() 函數將HELLO轉換爲小寫,用 upper() 函數將world轉換爲大寫,並用 concat() 函數將兩部分鏈接在一塊兒 *
select concat(lower('HELLO') ,upper('Word')) ; orm

-- 3.用 replace() 函數將 hello earth 短語中的 earth 替換爲 world *
select replace('hello earth' ,'earth' ,'world');it

-- 4.用 substr() 函數提取 hello world 短語中 llo w 部分的內容 **
select substr('hello world',3,5);ast

-- 5.用last_day函數返回當前月份的最後一天的日期(當前日期是變量now) **
select last_day(now());form

-- 6.用date_format將文本'2019-01-01'轉換爲正確的日期型日期 ***
select date_format('2019-01-01','%Y-%m-%d'); class

-- 7.用cast函數將emp表中的empno數字轉換爲文本型 ***
select cast(empno as char(4)) from emp;變量

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

相關文章
相關標籤/搜索