mysql教程(二)資料庫常用函式彙總

2021-10-12 01:35:25 字數 1005 閱讀 2558

函式①轉小寫:lower()

示例:select lower(ename) from emp;

②轉大寫:upper()

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

③擷取字串:substr(要擷取的字段,開始位置(從1開始),要擷取的長度)

④獲取字段長度:length()

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

示例: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

MySQL 資料庫常用函式

mysql內建的函式有很多,總結一下常用的,但是聚合函式我並未貼在此處 函式說明 abs x 返回x的絕對值 ceil x 返回不小於x的最小整數值即向上取整,返回值轉化為乙個bigint floor x 返回不大於x的最大整數值即向下取整,返回值轉換為乙個bigint round x 返回最接近於...

資料庫 MySQL 常用函式

常用的一些函式 1.日期和時間函式 1,curdate 返回當前日期 2,curtime 返回當前時間 3,month d 返回日期 d 中的月份值,範圍是 1 12 2.字串函式 1,char length s 計算字串 s 的字元數 2,upper s 把所有字母變成大寫字母 3,lower s...

MYSQL資料庫常用的函式

mysql資料庫常用函式 concat params 拼接字串 select concat a c b as 字串拼接 ifnull param1,param2 判斷欄位或表示式是否為空,為空,返回指定值,不為空,返回應有結果 select ifnull a null,0 isnull option...