mysql 内置方法

一.字符串函数
select concat(name,"age is",age) fromusers; 

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(idint,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表查看
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值