標籤:
一.字串函數
select concat(name,"age is",age) from users; insert(str,x,y,insert)//將字串x位置開始y個位置替換成insert select lower(str) upper(str)//轉化大小寫select * from user where upper(name)=‘AAA‘; left (str ,x) right(str,x)//分別返回左邊和右邊的x個字元select left ("abcdee",3),right("abcdedd",3),left("abcdedd",null); lpad(str,n,pad),rpad(str,n,pad)//用字串pad對str最左邊或最右邊補到n位 ltrim()substring(str,x,y)//返回字串中得第x位置起,取y個字元 二.數值函數abs(x) // 返回x的絕對值ceil(x) //返回大於x的最小整數floor(x)//返回小於x的最大整數mod(x,y) 返回x/y的膜rand() //0-1之間隨機數round(x,y)//返回參數x的四捨五入的有y位小數的值truncate(x,y) //返回數字x截斷y位小數的結果 三.日期函數用php的時間戳記來完成select curdate() curtime() now() unix_timestamp(now()) unix_timestamp(date)//unix時間戳記 from_unixtime() //與unix時間戳記相互轉換 week() year() hour() minute() …… select now()select unix_timestamp(now())select from_unixtiom(1293433835);select from_unixtime()select week(now())select minute/hour(curtime())select data_format(now(),"%Y-%m-%d %H%i%s") 四.流程式控制制函數create table salary(id int,salary decimal(9,2));insert into salary values(1,1000);*****if(value,t f)select if(salary>3000, ‘height‘,‘low‘)from salary;ifnull(value1,value2)select id,salary,ifnull(salary,0) from salarycase when[value1] then[result1]...else[default] end case when ...thenselect case when salary<=300 then ‘low‘ else ‘high‘ end from salary; 五.其他函數database()version() //查看資料庫目前的版本user() //查看目前使用者inet_aton(ip) //返回ip地址的網路自解序inet_ntoa() //返回網路自解序代表的ip地址password() //將字串加密,給mysql系統使用者用的select password (‘123456‘); md5() //給網站使用者加密select * from mysql.user \G;//從mysql庫中user表查看
mysql內建函數