mysql資料庫的函式

2021-08-19 10:08:12 字數 1999 閱讀 8138

2

--數學函式

3select

ceiling ( count(*)/

5.0) from news--

取大於結果的最小整數

4select

floor ( count(*)/

5.0) from news--

取小於結果的最大整數

5select

sqrt(2)--

數值開平方

6select

round(3.45645,2)

7select

abs(-

5):絕對值函式,取此數的絕對值,可以應用於資料庫中一些比較亂的值的加減操作。89

--字串函式

10select

lower('

rgfrg

')--

大寫字母變為小寫字母

11select upper('

ggfgrt

')--

小寫字母變為大寫字母

12select

ltrim()--

去掉左側字元空格

1314

select

rtrim()--

去掉字串右側空格

15select

left(title,5)from news--

從某列中左側起擷取多少長度的字串

16select

right(title,5)from news--

從某列中右側起擷取多上長度的字串

17select

substring(title,3,5) from news--

從某一列中第幾個字元開始擷取幾個字元

18select

reverse (title) from news --

翻轉某一列

19select

charindex('

中國',title)from news --

查詢目標內容在指定區域有沒有出現以及出現位置

20select

replace(title,'

中國','

美國')from news--

替換字串。例搜尋關鍵字並明顯標註

21select

stuff(title,3,4,'

chine

')from

news

22其他函式

23select

ceiling (rand()*

10)--

隨機生成-1之間的數字,可以以乘以的方式增大隨機數範圍

24select

len('

chine

')--

取字串長度

25select

getdate()--

獲取當前時間

26select

year(sbirthday)from student--

取時間年份

27select

month(sbirthday)from student--

取日期時間月份

28select

day(sbirthday)from student3--

取時間天

29select

datepart(yy,sbirthday)from student4--

yy,mm,dd分別代表年月日

30select

cast ('

123'

asint)--

轉換字串

MYSQL資料庫常用的函式

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

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...