Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2318175
  • 博文数量: 168
  • 博客积分: 3184
  • 博客等级: 中校
  • 技术积分: 3959
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-12 18:57
文章存档

2019年(1)

2018年(2)

2017年(3)

2016年(15)

2015年(10)

2014年(60)

2011年(1)

2010年(76)

分类: Mysql/postgreSQL

2015-06-24 17:20:03


(这是在网利宝项目中,逐渐总结归纳的内置函数
,大家感兴趣,可以扫码注册体验产品 
一.字符串函数

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表查看
阅读(7379) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~