mysql 檢視內建函式 mysql內建函式

2021-10-19 18:32:06 字數 1362 閱讀 2779

一、字串函式

1.concat(s1,s2....sn):把傳入的引數連線成乙個字串;

2.insert(str,x,y,str):從str的x位置開始,替換y長度的字串為str,select insert('abcdefg',2,3,'hello');

3.lower(str),upper(str):將字串轉換為大寫,小寫;

4.left(str,x) right(str,x) 返回str左邊(右邊)x個字元,x為null則返回null;

5.lpad(str,n,pad) rpad(str,n,pad)  用pad對字串str從最左邊(右邊)進行填充,直到總長度達到n ; select name,lpad(name,10,'#'),rpad(name,10,'(') from cats;

6.trim(),ltrim(),rtrim()去掉兩邊,左邊,右邊空格;select concat('1',trim('   abc   '),'2'),concat('1',ltrim('   abc   '),'2'),concat ('1',rtrim('   abc   '),'2')g;

7.replace(str,a,b) 在字串str中用字串b替換所有的字串a;

8.strcmp(s1,s2):如果s1比s2小,返回-1;如果s1比s2大則返回1;如果相等則返回0;

9.substring(str,x,y) 返回字串str中從位置x起,長度為y的子字串;

二、數值函式

abs(x):返回絕對值;

ceil(x):返回大於x的最小整數;

floor(x):返回小於x的最大整數;

mod(x,y):返回x與y的模;

rand():返回0-1之間的隨機數   select round(rand()*100);

round(x,y):返回引數x的y位小數的四捨五入結果;

truncate(x,y):返回數字x截斷為y位小數的結果;

三、日期函式

curdate() curtime() now();

select curdate();

select unix_timestamp(now());

select from_unixtime(1331110656);

select week(now()),year(now());

select hour(curtime()),minute(curtime());

select monthname(now());

select date_format(now(),"%y-%m-%d %h:%i:%s");

date_add(***,interval x day);

data_sub(***,interva; x day);

檢視內建函式幫助

1 type xx 判斷xx的型別 2 34 dir builtins 檢視所有的內建函式 56 78 dir 檢視某某內建函式的用法 如dir list 檢視列表的用法 910 1112 import timeit 13 timeit.doc 檢視doc屬性 1415 1617 dir timei...

mysql 內建函式

六 mysql函式 使用方法 select 內建函式 6.1 日期和時間函式 1.curdate 和current date 獲取當前日期 使用方法 select curdate 或select current date 2.curtime 和current time 函式 獲取當前時間 使用方法 ...

mysql常用內建函式 mysql常見內建函式

在mysql中有許多內建的函式,雖然功能都能在php 中實現,但巧妙的應用mysql內建函式可以大大的簡化開發過程,提高效率。mysql字串函式 concat string2 連線字串 lcase string2 轉換成小寫 ucase string2 轉換成大寫 length string str...