mysql內建函數

來源:互聯網
上載者:User

標籤:

 一.字串函數

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內建函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.