mysql整合函式 mysql內建函式

2021-10-18 12:09:10 字數 1363 閱讀 2128

一、字串函式

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);

mysql整合函式 mysql內建函式

一 字串函式 concat string2 連線函式 select concat id,name as id name from t1 lcase string2 轉換成小寫 ucase string2 轉換成大寫 length string2 string長度 ltrim string2 去除前端...

MySQL內連線排序

student1 學生表 grade1 年級表 result 考試成績表 subject 科目表 都在上乙個部落格 查詢參加考試的同學資訊 學號 姓名 科目號 成績 select s.studentno,studentname,subjectno,studentresult from student...

mysql 內連線查詢

例7.46 在fruits表和suppliers表之間使用內連線查詢,查詢之前,檢視兩個表的結構,select suppliers.s id,s name,f name,f price from fruits suppliers where fruits.s id suppliers.s id 例7...