星空网 > 软件开发 > 数据库

mysql内置函数汇总

 一.字符串函数

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  salary
case when[value1]  then[result1]...else[default] end 
case when ...then
select 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表查看

java企业级通用权限安全框架源码 SpringMVC mybatis or hibernate+ehcache shiro druid bootstrap HTML5

【java框架源码下载】






原标题:mysql内置函数汇总

关键词:MYSQL

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

涨价1.8万!就在刚刚,USPTO拟宣美国商标专利官费上涨!:https://www.kjdsnews.com/a/1448237.html
亚马逊产品评论几星才不算低?:https://www.kjdsnews.com/a/1449211.html
金融理财类产品首购攻略!:https://www.kjdsnews.com/a/1450211.html
如何布局独立站,出海品牌才能走得更远?:https://www.kjdsnews.com/a/1450212.html
漫谈|如何一句话惹毛跨境人?:https://www.kjdsnews.com/a/1450213.html
如何轻松打通海外众筹收款、结汇链路?:https://www.kjdsnews.com/a/1450214.html
最新研究:亚马逊、沃尔玛、Temu和Shein卖家重合率不断攀升:https://www.kjdsnews.com/a/1836554.html
三清山好玩乜?:https://www.vstour.cn/a/365182.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流